[iOS 7 Stanford 2013 Fall] Lecture 4 Foundation and Attributed String

More Objective-C

Creating Objects

1. alloc and int

2. Class Methods

3. Sometimes Both a Class Method and init Method Exist

4. Other Objects Creates New Objects


  • Sending messages to nil is (mostly) okay. No code executed.
  • Be careful if the method returns a C struct. Return value is undefined.


  • id means pointer to an object of unknown/unspecified type.
  • Really all object pointers are treated like id at run time.
  • Figuring out the code to execute when a message is sent at runtime is called “dynamic binding“.
  • Program crashs when someone is sending messages to an object that it doesn’t understand.
  • In order to be safe, we mostly use static type (e.g. NSString *, point out the type explicitly) and the compiler is really smart.
  • Compiler will not complain about assignment between an id and a statically typed variable.
  • Never use id *, because id is alreay a pointer.


  • Asking at runtime what class an object is or what messages can be sent to it.
  • isKindOfClass: inheritance included
  • inMemberOfClass: no inheritance
  • respondsToSelector: returns whether an object responds to a given method


SEL is the Objective-C “type” for a selector




  • Immutable
  • All objects in the array are held onto strongly
  • Shortcut to create: *@[]


  • Mutable version of NSArray
  • for-in


New syntax for creating an NSNumber in iOS 6: @()


  • I don’t know too much about this class.
  • Generic object wrapper for some non-object, non-primitive data types (i.e. C structs, interesting)


  • Bag of bits.
  • Used to save/restore/transmit raw data throughout the iOS SDK.


  • Used to find out the time right now or to store past or future times/dates.


  • No ordering.
  • Unique object



  • Immutable collection of objects looked up by a key (simple hash table).
  • All keys and values are held onto strongly by an NSDictionary.


  • Mutable version of NSDictionary.

Property Lists and NSUserDefault

  • It means any graph of objects containing only: NSArray, NSDictionary, NSNumber, NSString, NSDate, NSData.
  • SDK usually read property lists from somewhere or write them out to somewhere.

  • NSUserDefault: lightweight storage of property lists.


  • C struct (not a class)
  • Important location value NSNotFound.

UIFont and UIColor

  • Fonts in iOS 7 are very important to get right.
  • It is best to get a UIFond by asking for the preferred font for a given text style.

  • UIFontDescriptor: attempts to categorize a font anyway.


  • A NSString where each character has an NSDictionary of “attributes”.

Attributed String in UITextView and UILabel

2 thoughts on “[iOS 7 Stanford 2013 Fall] Lecture 4 Foundation and Attributed String

  1. Your style is very unique compared to other folks I’ve read
    stuff from. Thank you for posting when you’ve got the opportunity, Guess
    I will just bookmark this site.

Leave a Reply

Your email address will not be published. Required fields are marked *