present view controller programmatically (non-xib)

where SearchDisplayViewController is your (non-xib, code only) custom view controller. :

create table cells using xib

https://medium.com/@musawiralishah/creating-custom-uitableviewcell-using-nib-xib-files-in-xcode-9bee5824e722#.lbixf1y87 New File > Empty Interface Builder Then you’ll see the .xib file appear Click on the “right pane button” to make the Identity Inspector appear, because that’s where all the Interface Builder attributes are. If the right pane button is not there, go to menu View > Utilities > Identity Inspector. In the UI […]

computed property vs stored property (swift)

http://stackoverflow.com/questions/31515805/difference-between-computed-property-and-property-set-with-closure Swift: Beware of Computed Properties The computed property’s block is called each time you reference the variable Computed Property:

Stored Property ASSUMING THAT YOU DO NOT set the stored property, the stored property’s initialization closure is called once and only once when you do the first READ. Any other READS after that will […]

closures in swift

ref – https://developer.apple.com/library/prerelease/content/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html Chapter 9: Closures http://alisoftware.github.io/swift/closures/2016/07/25/closure-capture-1/ functions and closures are reference types Closures are reference types. This means that when you assign a closure to more than one variable they will refer to the same closure. This is different from value type which make a copy when you assign them to another variable or […]

custom tableview and cell in swift

UITableView and delegates create cellReuseIdendifier for cell string reuse id set up tableview and its delegates, implement delegate methods tableView.register(YourCell.self, forCellReuseIdentifier: “”) in cellForRow, tableView.dequeueReusableCell(withIdentifier: cellReuseIdendifier) as! SearchDisplayTableViewCell

UITableViewCell

difference between ? and !

ref – http://stackoverflow.com/questions/24083842/what-is-the-difference-between-string-and-string-two-ways-of-creating-an-opti Use ? if the value can become nil in the future, so that you test for this. variables with ? will degrade gracefully if nil. Use ! if it really shouldn’t become nil in the future, but it needs to be nil initially. If the variable is nil and you use exclamation, […]

Protocols in swift

http://stackoverflow.com/questions/24024466/how-do-i-make-a-class-conform-to-a-delegate-in-swift Learn Swift from Objective-C : Protocols and Delegation Defining a protocol

Conforming to protocol

Delegate it To create a delegate in obj-c, it uses id to mean that this class can be of any type, as long as it conforms to some protocol in the “” bracket. The variable name is delegate. […]

passing closures into functions as completion handlers

http://artsy.github.io/blog/2016/06/24/typealias-for-great-good/ Type aliases allow developers to define synonyms for pre-existing types. You can use typealias for most any type: classes, enums, structs, tuples, closures, etc. Here are a few examples:

Defining the handler type

Basically, we want to declare a completion handler that takes in bool as parameter, returns void Defining the function, […]

typealias in swift 3, closures

http://stackoverflow.com/questions/40183806/defining-typealias-in-swift-3-for-closures You can’t specify parameter names in closure typealias. So instead of:

You should use:

Downcast upcast using as! as?

demo http://stackoverflow.com/questions/29637974/whats-the-difference-between-as-as-and-as http://stackoverflow.com/questions/27570957/swift-difference-as-string-vs-as-string Setup Animal

MeatEater

VeggieEater

Upcast The upcast, going from a derived class to a base class, can be checked at compile time and will never fail. Upcast Example

Downcast A constant or variable of a certain class type may actually refer to an instance of a subclass behind […]