cs193p – Lecture #8 View Controller Lifecycle, Autolayout

Please note, this blog entry is from a previous course. You might want to check out the current one.

View Controller Lifecycle

  • viewDidLoad is called after instantiation and outlet setting (geometry is not set yet!) – use for setup
  • viewWillAppear is called before the view appears on screen (geometry is available) – use for layout setup and updates which happened while the view was off screen
  • viewDidAppear
  • viewWillDisappear – use for cleaning up and saving states
  • viewDidDisappear

Continue reading “cs193p – Lecture #8 View Controller Lifecycle, Autolayout”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Lecture #7 Multiple MVCs

Please note, this blog entry is from a previous course. You might want to check out the current one.

The seventh lecture addresses the interaction of multiple model-view controllers – especially navigation controllers.

Segues

The links between two view controllers are called segues. They always create a new instance of the called MVC and need to initialize that MVC e.g. using prepareForSegue.

Segues can also be prevented from happening using shouldPerformSegueWithIdentifier.

Popover

Where tab-bar, split-view and navigation controllers are view controllers, popovers are not. Though preparing popover segues works similar, their destruction needs special care, making the calling view controller the delegate.

The lecture and its slides are available via iTunes named “7. Multiple MVCs”. The code for the psychologist demo is available on GitHub and at Stanford.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Lecture #6 Protocols and Delegation, Gestures

Please note, this blog entry is from a previous course. You might want to check out the current one.

The sixth lecture contains theory interspersed with demos of the just learned topics.

Extensions

Extensions allow to add methods and properties to classes even if the source is not available. It is not possible to override existing methods and properties. New properties can not be used to store data.

Protocols

Protocols define APIs of methods and properties a caller should provide. It has no storage or implementation associated.

protocol SomeProtocol : class, InheritedProtocol1, InheritedProtocol2 {
    var someProperty: Int { get set }
    func aMethod(arg1: Double, anotherArgument: String) -> SomeType 
    mutating func changeIt()
    init(arg: Type)
}

Continue reading “cs193p – Lecture #6 Protocols and Delegation, Gestures”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Lecture #5 – Objective-C Compatibility, Property List, Views

Please note, this blog entry is from a previous course. You might want to check out the current one.

Objective-C Compatibility

Lecture #5 starts with theory on how Swift was built to be compatible with Objective-C and thus provides numerous seamless bridging methods:

  • NSString bridges to String
  • NSArray bridges to Array<AnyObject>
  • NSDictionary bridges to Dictionary<NSObject, AnyObject>
  • Int, Float, Double, Bool bridge to NSNumer – but not the other way around – use instead intValue, floatValue, doubleValue and boolValue

Additionally, it is possible to implicitly cast using as.

Continue reading “cs193p – Lecture #5 – Objective-C Compatibility, Property List, Views”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Lecture #3 – Applying MVC

Please note, this blog entry is from a previous course. You might want to check out the current one.

Lecture #3 continues the calculator demonstration, adding the model to the MVC pattern. In addition he shows how to use

  • enums,
  • simple initializers,
  • returning optionals,
  • dictionaries,
  • and tuples.

The lecture is available via iTunes named “3. Applying MVC”. The code for the demo is available on GitHub.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Lecture #2 – More Xcode and Swift, MVC

Please note, this blog entry is from a previous course. You might want to check out the current one.

Lecture #2 continues with the demonstration from the previous lecture showing:

  • how to use arrays,
  • computed properties,
  • the conditional statement switch,
  • functions as types,
  • various combinations of closure syntax defining functions “on the fly”,
  • method overloading – same method name, different arguments,
  • and more Autolayout.

Continue reading “cs193p – Lecture #2 – More Xcode and Swift, MVC”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail