19 Şubat 2015 Perşembe

Mobile Developer Questions and Answers

  • What’s the difference between directly calling a object’s method and perform 
Selector on a method? 

"performSelector": method allows you to send messages that aren’t determined until runtime. We can use main thread or another thread with"performSelector" or we can add delay time.

                    "directly calling a object’s method" : is a call to a known method on a known object. 

  • Do you use Automated Reference Counting? What are some of its 
(dis)advantages? 

I used only with third party library. ARC helps us to save time and skip the writing of deallocs and other memory management calls. When we develop in past projects without ARC, we must implement ARC for all of the class files so we lost a lot of time for past projects.

  • What does the @dynamic keyword do?  When might you use it? 

@dynamic: the keyword provides us to use accessor methods dynamically at runtime. It can be use for the Objective-C runtime functions

  • When might you use a CFArray/Dictionary instead of a NSArray/Dictionary? 
  
When we want to store non-reference-counted objects, we can create a CFArray or a CFDictionary.  


  • What is toll-free bridging and when is it useful? 

The some data structures are interchangeable. When we use the type on one side of the bridge, we can use the other. For example, we can create a CFString and then send NSString messages to it.

  • What’s a Objective C category and when might you use one? 

A category provides us to add methods to an existing class. We can extend the functionality of existing classes without subclassing

What usually (should) happens in a view controller when your app gets a low memory   warning? 

When the view controller gets a low-memory warning, it should be prepared to reduce its memory usage if it is not visible onscreen

  • What are blocks? What does the block keyword do? 

Blocks allow us to create distinct segments of code that can be passed around to methods or functions as if they were values. Blocks are Objective-C objects, which means they can be added to collections like NSArray orNSDictionary. They also have the ability to capture values from the enclosing scope, making them similar to closures or lambdas in other programming languages.



10 Şubat 2015 Salı

Swift Basics - Array and Dictionary


Simple Values

let -> make a constant
var -> make a variable 

In order to assign a value, we may not write type explicitly

Example:

    let constantValue = 20
        let constantValue2 : Int = 20

 Error:  Cannot assign to 'let' value 'constantValue'
constantValue = 30.5
 Error:  Cannot assign to 'let' value 'constantValue2’
        constantValue2 = 30

Change let to var
  var Value = 20
        var Value2 : Int = 20
      
 Error:  Type 'Int' does not conform to protocol 'FloatLiteralConvertible'
        Value = 30.5
  It’s OK
        Value2 = 30


Convert to “Int” type to “String” type

let stringValue = "The height of frame is "
        let height = 100
        let ​heightLabel​ = stringValue + String(height)
        
        
        println(​heightLabel​)

Convert to any type to String type basically.


  let height = 100
        let stringValue = "The height of frame is  \(height)"
        let ​heightLabel​ = stringValue
        
        
        println(​heightLabel​)


Change an item of array

        var arrayList = ["cat","dog","bird"]
        arrayList[1] = "penguen"
        
        for var i=0; i<arrayList.count; i++
        {println(arrayList[i])
        }

Add an item of array by using append method

        arrayList.append("bear")
 

Add an array of one or more compatible items
        arrayList += ["cow","butterfly"]

To insert an item into the array at a specified index:
        arrayList.insert("bee", atIndex: 4)

To remove an item from array
  arrayList.removeAtIndex(5)









3 Şubat 2015 Salı

Dynamic TableView Height using AutoLayout in Swift









iPhone has different sizes. In order to a tableview's height is suitable for any iPhone size, we can use autolayout.

An examle for Dynamic TableView Height using AutoLayout in mobile development

1. Add a tableview in view and implement UITableView Delegate and Data Source








class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource
...




2. Define tableview width

For Tableview width = iPhone width , we should define "equals width"



3. Add top and bottom space constraints

For Statusbar space, we should define "20"  top space
For horizontal space and vertical bottom space,  we should define "0". Since we define bottom space  as  "0" , tableview height has dynamic height.


4.  Control the storyboard preview for different iPhone sizes




5. Add an outlet object for TableView



5. Register tableview class


Add register class method in viewDidLoad

self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")


6. Add tableview methods for testing

  func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 100;
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
        
        cell.backgroundColor = UIColor.clearColor()
        cell.textLabel.text = "item \(indexPath.row)"
        
        
        
        return cell
    }
    
    func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
        println("Tablecell #\(indexPath.row)!")
    }


7. Result for iPhone 6




You can download from https://github.com/ozlemakalin/DynamicTableViewHeightSwift