본문 바로가기

IT/swift

핵심만 골라배우는 iOS9 프로그래밍 - swift2 에서 변경된 문법 메모

반응형

1. deprecated 된 함수

CGRectMake(0,0,200,200)

-->

CGRect.init(x:0, y:0, width:200, height:200)

 

CGAffineTransformMakeRotation(3.14)

-->

CGAffineTransform.init(rotationAngle: 3.14)

 

2. 접근방법 변경

UIColor.whiteColor()

->

UIColor.white

 

3. 호출변경

UIView.animateWithDuration(5.0, animations: {

->

UIView.animate( withDuration: 5.0 , animations: () -> Void )

 

4. 모듈변경

import XCPlayground

--> 

import PlaygroundSupport

 

** 종합예제

import UIKit
import XCPlayground
import PlaygroundSupport

let container = UIView(frame: CGRect.init(x: 0, y: 0, width: 200, height: 200))

//XCPlaygroundPage.currentPage.liveView = container

PlaygroundPage.current.liveView = container

container.backgroundColor = UIColor.white
let square = UIView(frame: CGRect.init(x: 50, y: 50, width: 100, height: 100))
square.backgroundColor = UIColor.red

container.addSubview(square)

UIView.animate(withDuration: 5.0, animations: {
    square.backgroundColor = UIColor.blue
    let rotation = CGAffineTransform.init(rotationAngle: 3.14)
    square.transform = rotation
})

5. 배열 선언 인자 변경

var nameArray = [String](count: 10, repeatedValue: "My String")

-->

var nameArray = [String](repeating: "My String", count: 10)

 

nameArray.insert("Han", atIndex: 0 )

-->

nameArray.insert("Han", at: 0 )

 

nameArray.removeAtIndex(2)

-->

nameArray.remove(at:2)

 

6. 딕셔너리 인자변경

bookDict.removceValueForKey("keyValue")

-->

bookDict.removeValue(forKey: "keyValue")

반응형