present view controller programmatically (non-xib)

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

create table cells using xib 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) 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 – Chapter 9: Closures 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


difference between ? and !

ref – 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 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 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 You can’t specify parameter names in closure typealias. So instead of:

You should use:

Downcast upcast using as! as?

demo Setup Animal



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 […]