2014-06-01から1ヶ月間の記事一覧

Swiftではclassにstatic変数が定義できない

struct, enumであれば、staticなpropetyがかけるけどclassはダメらしい。 computedなpropertyは書ける。 struct SomeStructure { static var storedTypeProperty = "Some Struct value." static var computedTypeProperty: Int { return 1+1 } } enum SomeEn…

inoutを使ったfunctionを利用してxcode6を落とす方法

落とすというか、落ちるんだけど。 コレは落ちない func addTwoInts(a: Int, b: Int) -> Int { return a + b } var mathFunction: (Int, Int) -> Int = addTwoInts inoutを入れると落ちる func addTwoInts(inout a: Int, b: Int) -> Int { return a + b } va…

Swiftのfallthroughはcaseの条件を評価してくれない

Swiftのswitch文は、どれかcaseに入ると後続のcaseは評価されずにswitch文を出る。 各case毎に暗黙的にbreakが書いてあるのと同じ挙動。 ただ、中には複数のcaseを実行したい場合もあるので、逆break的な意味でfallthroughが用意されている。 ところが、この…

Swiftの型予測が怖い

SwiftのArrayはtype safeで他の型を入れられないらしい。 If you create an array of Int values, for example, you can’t insert any value other than Int values into that array. Swift arrays are type safe, and are always clear about what they may…