enum Fruits: Int { case apple case orange case lemon } Objective-C Swift var fruits: Fruits = .apple switch fruits { case .apple: case .orange: case .lemon: } Fruits fruits = apple; switch (fruits) { case apple: case orange: case lemon: } enum ʹؔมΛهड़Մೳʂ
two = 1 << 1, three = 1 << 2 } Objective-C public struct OptValue: OptionSet { public let rawValue: Int public static let one = VaultAttributes(rawValue: 1 << 0) public static let two = VaultAttributes(rawValue: 1 << 1) public static let three = VaultAttributes(rawValue: 1 << 2) public init(rawValue: Int) { self.rawValue = rawValue } } Swift NSInteger val = three; if (val & one) { } else if (val & two) { } var opt: OptValue = .three opt.insert(.one) opt.contains(.two) opt.remove(.three)
event: String let url: String let date: String let participants: String let location: String let sponsor: String let hashtag: String } func fetch() { let urlString = "http://iphone.magickworx.com/iosendai.json" if let url = URL(string: urlString) { let semaphore = DispatchSemaphore(value: 0) (URLSession.shared.dataTask(with: url) { (data, response, error) in if let jsonData = data { do { let decoder = JSONDecoder() let json = try decoder.decode(iOSendai.self, from: jsonData) dump(json) } catch let error { dump(error) } } semaphore.signal() }).resume() semaphore.wait() } } fetch() ιʔείʔυΛίϯύΠϧ % swiftc fetch.swift fetch ίϚϯυ͕࡞͞ΕΔͷͰ࣮ߦ % ./fetch