This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Vehicle | |
| { | |
| var wheels: Int? { | |
| get { | |
| return nil | |
| } | |
| } | |
| class func vehicleFactory(wheels:Int) -> Vehicle | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ⭕️forEach, for-inに応答できるオブジェクトを生成できるクラスを作る。 | |
| 2つの文はループ枚にnext()を呼び出す。似たような関数anyGeneratorがあってその関数はGenerator型(closureを返すので、next()を呼び出すのと似ている)を返す。 | |
| 1️⃣SequenceTypeに準拠させる | |
| 2️⃣generateメソッドを定義(SequenceTypeが要求) | |
| 3️⃣戻り値はGeneratorTypeに準拠させる | |
| 4️⃣戻り値のクラスにはnext()メソッドを用意する。 | |
| let sine = SineClass() //ここでgenerate()は呼ばれないfor or forEachで一回だけ呼ばれる | |
| 💠使い方1 | |
| for x in sine { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| // class clusterの例:2種のクラスのインスタンスを生成できるfactory | |
| class MyColor { | |
| // var r: Int = 0, g: Int = 0, b: Int = 0 | |
| class func createWithColor(n: Int) -> MyColor { | |
| var res: MyColor? | |
| switch n { | |
| case 0: | |
| res = RedMyColor() | |
| case 1: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class KeyClass { | |
| var value:String | |
| init(_ value:String) { | |
| self.value = value | |
| } | |
| } | |
| extension KeyClass : Hashable { | |
| var hashValue: Int { | |
| return self.value.hashValue | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| enum Vehicle { | |
| case Car(windows: Int, wheels: Int) | |
| case Ship(windows: Int, funnels: Int, anchors: Int) | |
| case Plane(windows: Int, wheels: Int, wings: Int, engines: Int) | |
| } | |
| var aPlane: Vehicle = .Plane(windows: 1, wheels: 9, wings: 8, engines: 4) | |
| var voidPtr: UnsafePointer<Vehicle> = unsafeBitCast(&aPlane, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| func iterateEnum<T: Hashable>(_: T.Type) -> AnyGenerator<T> { | |
| var cast: (Int -> T)! // reference to clousure | |
| //print(($0).dynamicType) | |
| // what is $0 ?, Int, 0, 1, 2, 3, 4 for nil | |
| switch sizeof(T) { | |
| case 0: return anyGenerator(GeneratorOfOne(unsafeBitCast((), T.self))) | |
| case 1: cast = { unsafeBitCast(UInt8(truncatingBitPattern: $0), T.self) } | |
| // print($0.dynamicType);print($0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // case 1 | |
| //AppDelegate#application:didFinishLaunchingWithOptions | |
| NSSetUncaughtExceptionHandler {e in | |
| print(">>>>> ExceptionHandler OK") | |
| let log = NSString(format:"%@, %@", e.name, e.reason!) | |
| NSUserDefaults.standardUserDefaults().setValue(log, forKey: "failLog") | |
| } | |
| // case 2 | |
| // Closureを渡さなくても、swift関数の関数名を渡しても良い。ただし、NSSetUncaughtExceptionHandlerと同じスコープ内に | |
| // swift関数が無いとコンパイルエラー⁉️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let vc = ParamViewController(nibName : "ParamViewController", bundle : nil) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| if [ $# -ne 1 ]; then | |
| echo "making 120, 180px icons at current directory from specified file." | |
| echo "usage: makeicon file, one args required"; | |
| exit; | |
| fi | |
| BASEFILE=$1 | |
| echo $1 | |
| echo $BASEFILE | |
| sips -Z 120 $BASEFILE --out [email protected] |