Coord: Object { int x, y; } -‐ (void)set:(int)nx int: (int)ny @end @implementaTon Point -‐ (void)set:(int)nx int:(int)ny { x = nx; y = ny; } @end int main() { center = [Coord alloc] [center set 10, int 5] }
// 変数 let pi: Double = 3.14 // 定数 var city = "Tokyo" // 型推論論String型 let pi = 3.14 // 型推論論Double型 var year = 2014 var name = "JTF" var event = name + year // error var event = name + String(year) 16
*year = @"2014"; NSString *event = [event stringByAppendingString:year]; NSString *longName = @"July Tech Festa"; NSString *message = [NSString stringWithFormat:@"%@: %@", name, longName]; // SwiF var name = "JTF" var year = "2014" var event = name + year // JTF2014 var longName = "July Tech Festa" var message = "\(name): \(longName)" // JTF: July Tech Festa let x = 10, y = 3 let result = "\(x) / \(y) = \(x / y)" // 10 / 3 = 3 17
ª whereで細かい条件を制御できる。 ª 扱うことが出来るデータが多様である。 switch num { case 0: println("0") case 1, 2, 3: println("1, 2, 3") case 4...6: println("4, 5, 6") case let n where n % 2 = 0 && n < 10: println("8") default: println("other"); } 19