Objective-C: Any object can be nil
Swift: Optionals can be nil
#import <Foundation/Foundation.h> #import "Messengaer.h" #import "Package.h" int main(int argc, const char * argv[]){ @autoreleasepool { Messenger +spike = [[Messenger alloc] init]; Package *importantDocuments = [spike pickUpPackage]; NSLog(@"package contents: %@", importantDocuments.contents); } return 0; }
Objective-C and Swift approaches to mutability differ
– how mutability is achieved for a given type
– the probability of an unintended mutation propagating through a program
#import <Foundation/Foundation.h> #import "Messengaer.h" #import "Package.h" int main(int argc, const char * argv[]){ @autoreleasepool { NSArray *kayakingGear = [NSMutableArray arrayWithArray:@[@"halmet",@"paddle",@"boat", @"lifejacket"]]; [kayakingGear addObject:@"booties"]; NSLog(@"%@", kayakingGear); } return 0; }