2016年9月21日水曜日

Swift 3 DEATHよ

Xcode8でSwift 3になったので、そっちへの気づいた変更点を書いていくですよ。
コードのトランスレーターダとSwift 2.4だかも選べるけど、3にしない理由はないと思うので、3のだけ書きますよ。

ざっと見たけど、いろいろ変わりやがったな。
全てをチェックしてらんない。
関数の引数にラベルを付ける方向で、NSのサフィックスを取る方向で、関数名を短くしたり、関数名と引数のラベルをセットで意味を持たせたり…
書くのが楽になったり、わかりやすくなったりしてるのかどうかわかんないけど、ちょこちょこ変えないでほしいよね…

今までのアップデートだと、トランスレーターでちょっとした変更点は直してくれたけど、今回トランスレーターかけてもエラーになるところが山のように出たよ!!
何のためのトランスレーターだよ、この野郎!!
みなさん覚悟しましょう(≧∇≦)

indexPathのプロパティをいじる時は as NSIndexPathとしないといけない

let row = indexPath.row - alienPicsKeysArray.count

let row = (indexPath as NSIndexPath).row - alienPicsKeysArray.count

関数の第1引数のラベルがない場合、_ を付ける?

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {


func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

UIColorの指定がcolor()がいらなくなった


vc.bgSkyImageView.backgroundColor = UIColor.clearColor()

vc.bgSkyImageView.backgroundColor = UIColor.clear

列挙型の指定が先頭小文字になった

UIView.setAnimationCurve(UIViewAnimationCurve.EaseInOut)

UIView.setAnimationCurve(UIViewAnimationCurve.easeInOut)

Booleanのプロパティがis〜になった

vc.talkView.hidden = true
vc.cameraBtn.enabled = true

vc.talkView.isHidden = true
vc.cameraBtn.isEnabled = true

NSTimerがただのTimerに

どうやら全体的にNSのprefixがいらなくなったようだ。
var urouroTimer = NSTimer()

var urouroTimer = Timer()

関数名が変わった

finishTimer = NSTimer.scheduledTimerWithTimeInterval(rnd,
                    target: self,
                    selector: #selector(Cennina.finish),
                    userInfo: nil,
                    repeats: false)
            }


finishTimer = Timer.scheduledTimer(timeInterval: rnd,

                    target: self,

                    selector: #selector(Cennina.finish),
                    userInfo: nil,
                    repeats: false)
            }


CGRectMakeとかが CGRectとかに

CGPointMakeなんかもそう。
ラベルも必ずつくようになったのね。
vc.ufoImage.frame = CGRectMake(0, 0, 200 * vc.倍率, 200 * vc.倍率)

vc.ufoImage.frame = CGRect(x: 0, y: 0, width: 200 * vc.倍率, height: 200 * vc.倍率)

レイヤーのaddAnimationがaddに

vc.view.layer.addAnimation(transition, forKey: nil)

vc.view.layer.add(transition, forKey: nil)


Switch文の書き方

optionalな値を判断するcaseの値の前に?が。めんどくせえ!
switch month {
        case 1: //1
            msgJanuary(day)
        case 2:
            msgFebruary(day)
        default:
            print()
        }

switch month {
        case ?1: //1
            msgJanuary(day!)
        case ?2:
            msgFebruary(day!)
        default:
            print()
        }

UserDefaultsの書き方

setする値が何でもsetだけで良くなったのだね。
読む時は型によって.object とか .boolとか指定しないといけない。
let ud = NSUserDefaults.standardUserDefaults()
if let _ = ud.objectForKey("currentStage")
ud.setBool(soundFlag, forKey: "soundFlag")
ud.setObject(currentStage.rawValue, forKey: "currentStage")

let test = ud.objectForKey("currentStage")

let ud = UserDefaults.standard
if let _ = ud.object(forKey: "currentStage")

ud.set(soundFlag, forKey: "soundFlag")


ud.set(currentStage.rawValue, forKey: "currentStage")

let test = ud.object(forKey: "currentStage")

0 件のコメント:

コメントを投稿