Smart Device/Swift42 Swift Objects and Classes #3 -Class에서의 Method는 함수와는 다른 중요한 차이가 하나 있다. 함수에서 인자는 함수 내에서만사용되지만 Class의 Method는 첫번째 인자를 제외하고는 Method를 호출할 때에도 별도의 이름을지정해 사용될 수 있다. Method안에서 사용되어지는 두번째 인자명을 지정할 수도 있다. class Counter { var count: Int = 0 func incrementBy(amount: Int, numberOfTimes times: Int) { count += amount * times }}var counter = Counter()counter.incrementBy(2, numberOfTimes: 7) - optional values을 사용할 때에는 methods, properties, a.. 2014. 6. 29. Swift Objects and Classes #2 - Properties getter setter - Properties properties는 getter와 setter를 가진다. class NamedShape { var numberOfSides: Int = 0 var name: String init(name: String) { self.name = name } func simpleDescription() -> String { return "A shape with \(numberOfSides) sides." }} class EquilateralTriangle: NamedShape { var sideLength: Double = 0.0 init(sideLength: Double, name: String) { self.sideLength = sideLength super.init(name: name) n.. 2014. 6. 24. Swift Numeric Types - Boolean Types - Integer Types - Floating Point Types 2014. 6. 12. Swift Dictionary - Dictionary Dictionary는 key-value쌍의 정렬되지 않은 Generic Type의 Collection으로 사용된다. Dictionary Key들의 모든 값들은 KeyType과 호환되어야 하고, Dictionary의 모든 Value들 또한 ValueType과 호환되어야 한다. * init(minimumCapacity: = 2) Dictionary는 key-value 쌍으로 초기화되어야 한다. init(minimumCapacity: Int = 2) 예) var emptyDictionary = Dictionary() // constructs an empty dictionary ready to contain String keys and integer values * Accessing an.. 2014. 6. 12. 이전 1 ··· 4 5 6 7 8 9 10 11 다음