Join Simon Allardice for an in-depth discussion in this video Mapping properties, part of Comparing Swift and Objective-C.
- In Objective C defining a property in a class…will synthesize getter and setter methods,…and we can use those methods to access or change a property,…or we could use dot syntax, which, in Objective C…is simply a shortcut that will use…the getter and setter methods behind the scenes.…In Objective C if I had a class called Player,…instantiated that and it had a NSString property defined…called alias, I could either use dot syntax to set its value…or I could use the equivalent setter method…which would be automatically generated…as the name of the property, alias,…but with the word set added to the start.…
And if I want to get the value I could again just dot syntax…or use the getter method, which in Objective C…is just the name of the property,…there's no get at the start.…The properties are simpler in Swift.…As with methods we just use dot syntax.…I can instantiate and then…use dot syntax to set or get the value.…No parentheses are needed on any of the information…on passing in because they use this property format.…
Need a refresher on either language? Check out Swift Essential Training and Objective-C Essential Training.
- Exploring the interoperability of Swift and Objective-C
- Comparing language syntax
- Understanding how each language uses objects and methods
- Bridging arrays, dictionaries, and numbers
- Dealing with nil return types from Objective-C methods
- Working with NSError in Swift
- Working with Swift and Objective-C strings
- Adding Swift to an existing Objective-C project
- Inheriting between languages