"EPCF4ZTUFNT 5PLZP w -JPOCSJEHF 5PLZP w 2VBSL 5PLZP%FOWFS w )VNNJOHCJSE$PNNVOJDBUJPOT .U7JFX 64" w 'BDU*OUFSOBUJPOBM 7BODPVWFS $BOBEB w 1FSMF4ZTUFNT 5PSPOUP $BOBEB FUD
Int? { guard let a = a, let b = b where a >= 0 && b >= 0 else { return nil } return a + b } w JGMFUͰ̌Ҏ্Λอূ͢Δ func add(a: Int?, _ b: Int?) -> Int? { if let a = a, let b = b where a >= 0 && b >= 0 { return a + b } return nil }
0 as Int: print("zero as an Int") case 0 as Double: print("zero as a Double") case let someInt as Int: print("an integer value of \(someInt)") case let someDouble as Double where someDouble > 0: print("a positive double value of \(someDouble)") case is Double: print("some other double value") case let someString as String: print("a string value of \"\(someString)\"") case let (x, y) as (Double, Double): print("an (x, y) point at \(x), \(y)") case let movie as Movie: print("Movie:'\(movie.name)'") default: print("something else") } }
Integer(Int) case Float(Swift.Float) case Dictionary([Swift.String: Element]) case Array([Element]) case Null } let integer = Element.Integer(42) let city = Element.String("Tokyo") let cities = Element.Array([city]) let dictionary = Element.Dictionary(["items": array])
case .String(let string) = element1 { print("\(string)") } w 0QUJPOBMͳ߹ͰऔΓग़ͤ·͢ let element: Element? = … if case .String(let string)? = element1 { print("\(string)") }
= Element.Dictionary(["name": name]) let members = Element.Array([john]) let group = Element.Dictionary(["members": members]) w ҰൃͰऔΓग़ͤΔ if case .Dictionary(let group) = group, case .Array(let members)? = division["members"], case .Dictionary(let member)? = members.first, case .String(let name)? = member["name"] { print("\(name)") // John }
= 0 ; i < 100 ; { print("\(i)") if (i * i) % 2 == 0 { i += 1 } else { i += 2 } } // Swift 3.0 ready var i = 0 while i < 100 { print("\(i)") if (i * i) % 2 == 0 { i += 1 } else { i += 2 } }