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

MapStack - lesson 1

leveton
March 11, 2016
42

MapStack - lesson 1

leveton

March 11, 2016
Tweet

Transcript

  1. Strong vs Weak dog analogy A dog will not run

    away as long as at least one person is holding on to its leash. So the dog’s retain count is at least 1. When no one is holding onto that leash, the dog will run away (dealloc). Many people can have leashes hooked to the dog (though that would be weird).
  2. Strong vs Weak dog analogy You can get/set properties and

    call methods on the object with both strong and weak references. So.. both a person holding the leash (strong property) and a person standing near the dog but not holding the leash (weak property) can pet the dog, or kick the dog, or give the dog commands or see the dog.
  3. Strong vs Weak dog analogy If you have a weak

    ownership of something it means that something else has strong ownership of that object.
  4. Automatic Reference Counting Objective-C’s “garbage collector” works by counting the

    number of strong pointers to an object. When the count is 0, the object is destroyed (deallocated). This is why our circle object a few slides ago perished. It’s retain count had reached 0 because nothing had a strong pointer to it.
  5. Automatic Reference Counting Allocating a new Car object, it has

    a retain count of 1. It’ll be 1 as long as it’s in scope of held strongly by another object. Assigning a strong property (e.g. an instance variable) to carObject ups the retain count to 2. When the scope ends (when the method returns), the memory mgmt system decreases the retain count to 1, but it still isn’t 0 because of its assignment to the instance variable.
  6. Getters and Setters @property allows built-in access to an object’s

    data. data can be ‘get’ and ‘set’ via dot notation or old-school message passing.
  7. Used often by UIKit Usually used so that you don’t

    have to instantiate a new object to call some method. class methods
  8. Used often in managers (networking, core data, etc) Used for

    custom initialization (more rare) class methods
  9. Initializers The ‘if-self-return-self dance’. The common way to initialize an

    object. ‘super’ is ‘self’ but it starts looking at its superclass's method table for implementation.
  10. Initializers Why this convoluted dance... - It’s the standard Apple

    initializer pattern which covers the 3 possibilities: 1) returns self (what happens the VAST majority of the time). 2) returns nil (something went horribly wrong). 3) returns an instance of a different class (rare). - Your super class may fail to initialize. - If self is nil, and you don’t return nil, you will crash, returning nil allows you to fail gracefully.
  11. Core geometry CGPoint struct CGPoint { CGFloat x; CGFloat y;

    }; CGSize struct CGSize { CGFloat width; CGFloat height; }; CGRect (combines CGPoint and CGSize) struct CGRect { CGPoint origin; CGSize size; }; Remember, most UIKit objects are subclasses of UIView
  12. Core geometry Remember, most UIKit objects are subclasses of UIView

    and UIView has a frame property which is just a CGRect
  13. Core geometry Views also have a bounds property. Also of

    type CGRect. The difference is that a view’s frame is relative to the superview while a view’s bounds is relative to itself. Therefore the origin of a bounds is always 0,0. A views bounds is often the same as its frame BUT a rotated view will have a different bounds.size than frame.size.
  14. Core geometry Therefore the origin of a bounds is always

    0,0. A view’s bounds is often the same as its frame BUT a rotated view will have a different bounds.size than frame.size.
  15. CG helper methods CGRectMake() - makes a rectangle with bounds

    and size CGRectGetWidth(), CGRectGetHeight() - self-explanitory CGRectGetMaxX() - gets the width + the x-offset CGRectGetMaxY() - gets the height + the y-offset
  16. Core geometry Remember, most UIKit objects are subclasses of UIView

    which has a frame property of type GCRect. Core Geometry is like reading - left to right, top to bottom
  17. retina, retina-HD, pixels and points One point does not necessarily

    correspond to one physical pixel. On a device with a retina screen, a line that is one point wide may actually result in a line that is two physical pixels wide.
  18. retina, retina-HD, pixels and points @1x, @2x, @3x.. You will

    see these suffixes appended to to images. What do they mean? The Asset Catalog will automatically match up images suffixed with @2x and @3x with retina and retina HD respectively: .
  19. Let’s get started with our project The final project will

    be a tabbar-based location services app. Here’s how our app would look on The App Store:
  20. UITabbarController and UIViewController UITabbarController is a subclass of UIViewController. It

    has an array property with UIViewController elements which are shown along the bottom of the device.
  21. UITabbarController and UIViewController In our app delegate, cmd+click into setViewControllers

    and read the following comment from Apple: “// If the number of view controllers is greater than the number displayable by a tab bar, a "More" navigation controller will automatically be shown.”
  22. UITabbarController and UIViewController Our four UIViewControllers will control views for:

    1) Maps 2) Locations 3) Favorites 4) Settings If you’ve done web development, think of view controllers as the html of an iOS app.
  23. UIWindow, UITabbarController and it’s UIViewControllers This is a 3D image

    screenshot of what our settings view controller will look like by the end of the project. Switch to the lesson 8 branch to see it in action.