collectiontype

· iOS/Swift
Swift의 Dictionary타입은 Foundation의 NSDictionary를 bridge한 타입. 빈 Dictionary 생성 var namesOfIntegers = [Int: String]() namesOfIntegers[16] = "sixteen" namesOfIntegers = [:] 리터럴로 Dictionary 생성 var airports: [String: String] = = ["YYZ": "Toronto Pearson", "DUB": "Dublin"] Dictionary 접근, 변경 print("The airports dictionary contains \(airports.count) items.") // 빈 Dictionary 확인 if airports.isEmpty { print("..
· iOS/Swift
Set은 Array와 유사하지만 같은 값을 또 넣을 수 없다는 특징이 있는 Collection Type입니다. '집합'을 표현하고 이에 대한 처리를 할 때 유용합니다. Set 형태로 저장되기 위해서는 반드시 타입이 hashable이어야 합니다. Swift에서 String, Int, Double, Bool 같은 기본 타입은 기본적으로 hashable입니다. Swift에서 Set 타입은 Set으로 선언. 빈 Set 생성 var letters = Set() letters.insert("a") letters = [] 배열 리터럴로 Set 생성 var favoriteGenres: Set = ["Rock", "Classical", "Hip hop"] // 타입 추론으로 생략 가능 var favoriteGenres:..
· iOS/Swift
배열의 생성 // 빈 배열 생성 var someInts = [Int]() // 3을 추가 someInts.append(3) // 배열을 비움. Type은 Int로 유지됨 someInts = [] 기본값으로 빈배열 생성 var threeDoubles = Array(repeating: 0.0, count: 3) // threeDoubles : Double 타입의 [0.0, 0.0, 0.0] 배열끼리 합 var anotherThreeDoubles = Array(repeating: 2.5, count: 3) // anotherThreeDoubles : [2.5, 2.5, 2.5] var sixDoubles = threeDoubles + anotherThreeDoubles // sixDoubles : [0.0, ..
SwiftyCody
'collectiontype' 태그의 글 목록