Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MapSwift - lesson 1

leveton
May 03, 2017
48

MapSwift - lesson 1

leveton

May 03, 2017
Tweet

Transcript

  1. Inheritance All classes are descended from other classes except for

    the root class. Class hierarchy for a UILabel Cocoa object NSObject -> UIResponder -> UIView -> UILabel Everything in cocoa touch descends from NSObject. All cocoa objects are related to NSObject. Car is not part of the cocoa touch framework, so it’s a new base object.
  2. Inheritance NSObject -> UIResponder -> AppDelegate -> UIWindow -> UIViewController

    -> UIView -> UILabel These last 3 are what you’ll be working with most of the time. You’ll also spend some time with AppDelegate. UIResponder and UIWindow, not so much.
  3. Polymorphism Objects have ownership of their methods and properties so

    that methods with the same name but different owners can do different things. A Car object and a House object both have a numberOfDoors public property but the runtime doesn’t get confused.
  4. Introspection Objects know about their own abilities Objects have methods

    like isKindOfClass, isMemberOfClass, respondsToSelector, etc. These methods reveal meta info about the object - different from most methods that reveal and manipulate program data or properties.
  5. Delegation from the Apple Docs: “A delegate is an object

    that acts on behalf of another object when the first object encounters an event in a program.” The delegate pattern so important and popular in Apple land that we’ll be using it and referring back to it throughout the course.
  6. Primitives vs Objects Objects are like turbocharged C structs. Swift

    structs are more powerful and do many things that Swift objects do. Some diffs... Do not support inheritance. Are pass-by-value instead of pass-by-reference. Are a bit faster because objects are dynamically allocated. Have a larger memory footprint because new memory is used on assignment.
  7. Automatic Reference Counting ARC is how Swift manages memory. Each

    object on the heap has a retain count. If the retain count reaches 0, the object is deallocated. free() is called behind the scenes.
  8. Automatic Reference Counting An object that is a local variable

    inside of a function has a retain count of 1 until that function returns. Objects that are properties have a retain count of 1 by default. For each owner that an object has, its retain count in incremented by 1.
  9. Memory management and ARC Let’s breakdown these property declarations: var

    - compiler declaration that our property is mutable. strong - increments this pointer’s retain count by one. Swift objects are strong by default. weak - does not increment this pointer’s retain count by one. <String> - indicates that the elements in the array are of type String. Think of angle brackets as ‘must contain, must be, must conform to’ ? - indicates that carA is an optional property, so it’s nil until it’s initialized. ! - indicates that arrayA is an unwrapped optional, so you’re guaranteeing that it’s not nil. By placing the exclamation mark in the declaration, you don’t have to place it everytime you use arrayA.
  10. Memory management and ARC It’s a “!” because it’s dangerous,

    you are responsible for making sure it’s initialized. At this point the reference counts of arrayA and carA are still 0 because they’re nil. The view was loaded into memory and arrayA immediately initialized. Now it’s reference count is 1.
  11. iOS > Tabbed Application Product Name: ‘MapSwift’ Organization Name: your

    name Organization id and bundle id: reverse domain of your name Language: Swift Devices: iPhone Check ‘Create a Git Repository’ Creating MapSwift