swift 1.1 和 1.2版的差異 和修護的方法

swift 1.1 和 1.2版的差異 和修護的方法

因為swift 1.1 和 1.2版因為版本的升級,導致舊版的會有問題,在這裡列出有問題的地方、差異和修護的方法


1.2版有問題的地方:

let scene = archiver.decodeObjectForKey(NSKeyedArchiveRootObjectKey) as GameScene

答案:

 

let scene = archiver.decodeObjectForKey(NSKeyedArchiveRootObjectKey) as! GameScene


 

1.2版有問題的地方:

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {

答案:

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {


1.2版有問題的地方:

override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {

答案:

override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {


1.2版有問題的地方:

override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {

答案:

override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {

   


1.2版有問題的地方:

var touch: UITouch = touches.allObjects[0] as UITouch


var
location: CGPoint = touch.locationInNode(self)

答案:

if let touch =  touches.first as? UITouch {

            let location=touch.locationInNode(self)

           // . ....

}


1.2版有問題的地方:

if let path = NSBundle.mainBundle().pathForResource(file, ofType: "sks") {

答案:

if let path = NSBundle.mainBundle().pathForResource(file, ofType: "sks") {


1.2版有問題的地方:

..

答案:

..


1.2版有問題的地方:

if let path = NSBundle.mainBundle().pathForResource(file, ofType: "sks") {

}

答案:

if let path = NSBundle.mainBundle().pathForResource(file as String, ofType: "sks") {

}

 


1.2版有問題的地方:

func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {

}

答案:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

}


1.2版有問題的地方:

var value7:Byte=20

答案:

var value7:UInt8=20


 

 

 

Swift
CH01 簡介CH02 安裝與下載CH03 我的第一個程式CH99 問題集