1.OC 没有tupple返回, swift 有
2.Instantiating Objects
var myDate = NSDate()
swift 没有指针,没有alloc init用()(new)
NSDate *myDate = [[NSDate alloc] init]; OC
3.Calling methods
[myObject method]; 方括号包括整个方法
myObject.method() 点语法必须有参数小括号
4.Calling methods one parameter
[myObject methodWithParameter:123];
myObject.methodWithParameter(123)
5.Calling method with two parameters
[myAVQueuePlayer insertItem:newSong afterItem:currentSong];
myAVQueuePlayer.insertItem(newSong,afterItem:currentSong)
swift第一个形参在外,其他在括号里
6.Initializer methods
OC: [[NSURL alloc] initWithString:@”http://bd.com"];
SW:NSURL(string:”http://bd.com") 没有了initWith,直接类名加括号参数
7.factory methods
OC.没有alloc/init: [NSURL URLWithString:@”http://bd.com"];
SW.不能用NSURL.URLWithString:(“http://bd.com")没有swift版本
还用NSURL(string:”http://bd.com") ,只用init版本,有swift版本
8.using failable initialization will be mapped to optional value
var myURL:NSURL? = NSURL(string:”http://bd.com")
1 | if(myURL != nil) { |
myURL?.lastPathComponent
1 | If let myURL:NSURL = NSURL(string:"http://bd.com"){ |