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

Lecture #6: Multiple MVCs and Segues

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

Lecture six is named “6. Multiple MVCs and Segues (October 13, 2011)” and can be found at iTunes. Its slides are available at Stanford.

It starts with a continuation of the demo from the second half of the previous lecture, adding features to Happiness namely delegates. The code for this demo is available directly at Stanford, and github.
Continue reading “Lecture #6: Multiple MVCs and Segues”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Lecture #5: Protocols and Gestures

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

The first lecture of the third week of the course is named “Protocols and Gestures (October 11, 2011)” and can be found at iTunes. Its slides are available at Stanford.

It starts with a theoretical part presenting

  • Autorotation,
  • Protocols and
  • Gesture Recognizers.

When a device rotates you can choose how your application should react:
Continue reading “Lecture #5: Protocols and Gestures”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail