Learn the distinguishing language features of OC
They differ substantially in their handling of nil, their approach to mutability and object typing.
1. OC和Swift共享iOS Frameworks和Design Patterns,但是在OC中,所有的对象都可以为nil,而在Swift中,只有Optioal类型的对象才可以为nil。
2. In swift, constants are constant, variables vary, and by default we are encouraged to favor constants. In OC mutability is by certain classes and property attributes; by default all objects are mutable.
OC classes with limited mutability include all Foundation collections. For example, NSStrings are not mutable; to make a change to a string one must either make a new string or use NSMutableString. The same goes for NSArray and NSMutableArray, NSDictionary and NSMutableDictionary, NSSet and NSMutableSet.
3. Swift is statically typed. The type of every entities known at compile time.
OC uses a combination of static and dynamic typing. The types of the majority of objects are declared at compiled time. In fact, it's required that every of object have a type.
How objects are bound to the methods the invoke?
In swift, method binding or method resolution happens at compile time.
In OC, methods in the objects invoking them are not bound until runtime.
What happens when you invoke a method on a nil pointer in Objective-C?
Sample Response
Nothing! It's ok to send a message to nil in Objective-C. There are no nil pointer exceptions. If the method invoked returns a number or a pointer, the value returned will be 0.
Does Objective-C have multiple inheritance? How does inheritance affect iOS architecture?
Sample Response
Objective-C has single inheritance; classes can only inherit from one other class. Both Swift and Objective-C achieve something akin to multiple inheritance through the widespread use of protocols. For example, view controllers commonly conform to multiple protocols like the TableViewDelegate and DataSource protocols as well as the TextFieldDelegate protocol.