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
| struct A<T> { | |
| let t: T | |
| struct S1 { | |
| let t: T | |
| } | |
| struct S2<T> { | |
| let t: T | |
| } | |
| func xxx() -> S1 { | |
| return S1(t: t) |
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
| do { | |
| struct A {} | |
| struct B { let a: A } | |
| struct C { let b: B } | |
| // 何もしないと、「AをinjectしたC」を作りたいときこうなる | |
| let c = C(b: B(a: A())) | |
| // 「CがBに依存している」という知識は、本来Cを使う場合は不要なはず | |
| // そのため、依存グラフを解決する Resolver を考える |
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 PopTeamEpic: Int { | |
| case ポ,プ,テピ,ピック | |
| } | |
| struct 蒼井翔太: Sequence, IteratorProtocol { | |
| mutating func next() -> PopTeamEpic? { | |
| return PopTeamEpic(rawValue: Int(arc4random_uniform(4))) | |
| } | |
| } |
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
| enum AsyncState<T, E: Error> { | |
| case inProgress | |
| case success(T) | |
| case failure(E) | |
| } | |
| extension Observable { | |
| static func from<T, E: Error>( | |
| trigger: PublishSubject<Void>, | |
| execute asyncProcess: @escaping () -> Single<T>, |
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
| struct A { | |
| var hoge = "a" { | |
| didSet { print("fixed", hoge) } | |
| } | |
| // たとえmutatingなfuncの中でも、 | |
| mutating func fix() { | |
| // クロージャの中ではselfの書き換えはできない | |
| DispatchQueue.main.async { | |
| self.hoge = "b" // Error: Closure cannot implicitly capture a mutating self parameter |
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 trigger = PublishSubject<Void>() | |
| func fetch() -> Single<String> { | |
| return Single.create { observer in | |
| print("🛫") | |
| DispatchQueue.global().async { | |
| usleep(2_500_000) | |
| print("🛬") | |
| observer(.success("レスポンス")) | |
| } |
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 | |
| struct Default: LocalizedError { | |
| } | |
| struct E: LocalizedError { | |
| let errorDescription: String? = "e" | |
| } | |
| struct F: LocalizedError { | |
| let failureReason: String? = "f" | |
| } | |
| struct R: LocalizedError { |
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
| struct A { | |
| struct B { | |
| var i: Int | |
| } | |
| var b: B | |
| var xxx: B { | |
| get { return b } | |
| set { b = newValue } | |
| } |
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
| struct Hoge { | |
| var int: Int | |
| } | |
| // ----------------------- | |
| // Array 編 | |
| var arr: [Hoge] = [ | |
| Hoge(int: 1), | |
| Hoge(int: 2), |
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
| /// Fugaをprivateに保つために作るTest用ラッパー。Fugaと同じファイル内に書く | |
| final class FugaTester { | |
| private let base: Fuga | |
| init(args: (x: Int, y: Int)) { | |
| base = Fuga(x: args.x, y: args.y) | |
| } | |
| var x: Int { return base.x } | |
| var y: Int { return base.y } | |
| func doSomething(with string: String) -> String { | |
| return base.doSomething(with: string) |