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

MapSwift - lesson 2

leveton
May 08, 2017
26

MapSwift - lesson 2

leveton

May 08, 2017
Tweet

Transcript

  1. Xcode crash course Each will get its own slide Navigator

    Main Window Debug area Utilities Devices Organizer
  2. Navigator Project navigator - Files, asset catalogs, xibs, plists, frameworks

    Symbol navigator - Mostly classes Find navigator - Search Issue navigator - Warnings and errors Test navigator - Test files Debug navigator - Debugging Breakpoint navigator - Breakpoints Report navigator - Build, debug, and run logs
  3. Main Window Meta panel - (Shown right, studying this will

    help in understanding OOP) Standard editor - shows one file at a time Assistant editor - defaults to show the header and implementation files Version editor - shows changes since the last commit
  4. 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).
  5. 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.
  6. Strong vs Weak dog analogy If you have a weak

    ownership of something it means that something else has strong ownership of that object.
  7. Automatic Reference Counting Swift’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 the circle object from a few slides ago perished. Its retain count had reached 0 because nothing had a strong pointer to it.
  8. 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 or held strongly by another object. In the above case, car’s retain count is one until the function returns. Assigning a strong property (e.g. an instance variable) to car ups the retain count to 2 and so it’ll still be in memory when the function returns.
  9. Playgrounds Perfect for testing logic. Ok for working with complicated

    frameworks. It uses a combination of the static analyzer and a quick compile.
  10. getters and setters review This is also a computed property

    but we don’t need to change some other property if this property is set.
  11. Getters and Setters Getters and setters allow you to execute

    logic that is related to whatever variable is being assigned or fetched.
  12. If you don’t need a setter This is also a

    computed property but we don’t need to change some other property if this property is set.
  13. What if you just want a setter? You can use

    ‘willSet’ or ‘didSet’ to make some calculations when the ‘model’ variable is changed.
  14. if let vs guard let if let looks for true

    while guard let looks for false.
  15. if let vs guard let - bouncer pattern guard allows

    you to do each of your checks, and return if any aren’t met.
  16. if let vs guard let guard lets you cleanly unwrap

    optionals. In a function, guard must return and in a loop, guard must break or continue.
  17. The underscore _ Used as a placeholder Notice how we

    have no need for the index in the loop.
  18. The underscore _ Used when we don’t want to force

    the caller to declare a parameter Notice how we can skip the ‘first’ declaration when we override the superclass’s method
  19. open vs public As of Swift 3, open and public

    are the same unless you are writing a framework. If writing a framework, you must declare open any class or class member that you want to allow users to access. For us, open and public will be the same. public is the default.