Swift vs. Objective-C
1.1 Similarities between Swift and Objective-C
-
Most of the concepts that were present in OC, such as reference counting, ARC (automatic reference counting), attributes, protocols, interfaces, initializations, extended classes, named parameters, anonymous functions, etc., continue to be valid in Swift (probably in a different term at most).
-
Swift and Objective-C share a runtime environment, and the type of Swift can be bridged to Objective-C (hereinafter REFERRED to as OC) and vice versa
1.2 Advantages of Swift
- Swift focuses on security, OC on flexibility
- Swift focuses on protocol oriented programming, functional programming and object-oriented programming, while OC focuses on object-oriented programming
- Swift focuses on value types, OC on Pointers and references
- Swift is statically typed and OC is dynamically typed
- Swift is easy to read, the file structure and most of the syntax are simple, only. Swift files, do not need semicolons at the end
- Optional types in SWIFT are used for all data types, not just classes. More secure and concise than nil in OC
- Generic types in Swift are more convenient and generic than in OC, where you can only add generics for collection types
- Quick and convenient high-order functions in SWIFT (functional programming) (Swift’s standard array supports three high-order functions: Map, filter and reduce, as well as the flatMap extension of Map)
- Swift has added two new permissions to refine permissions. Open > Public > Internal (default) > Fileprivate > private
- Tuples unique to Swift combine multiple values into composite values. Values within a tuple can be of any type and are not required to be of the same type.
1.3 Deficiencies of Swift
- Version instability
- The proportion of company use is not high, the proportion of users is low
- Some grammars can specify only one format, without having to do this or that. Like Go, everything is banned (Go is a bit extreme), one specification, easy for teamwork and reading other people’s code.
1.4 Values VS references
String, Array, and Dictionary in Swift are structures, so assignments are directly copied, whereas NSString, NSArray, and NSDictionary in Objective-C are classes, so they use references.