This file contains 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
$ swiftc -emit-silgen -sdk $(xcrun --show-sdk-path --sdk macosx) date.swift > date.sil |
This file contains 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 PartialFunction<A, B> { | |
let f: A throws -> B | |
init(_ f: A throws -> B) { | |
self.f = f | |
} | |
} | |
extension Optional { | |
func collect<B>(f: PartialFunction<Wrapped, B>) -> Optional<B> { | |
if let res = try? self.map(f.f) { |
This file contains 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
@_exported import class BrightFutures.Future | |
import func BrightFutures.future | |
import var BrightFutures.ImmediateOnMainExecutionContext | |
import RealmSwift | |
protocol RepositoryImplType { | |
func runWrite(f: (Realm) throws -> Void) -> Future<Void, RepositoryError> | |
func runRead<T>(f: (Realm) throws -> T) -> Future<T, RepositoryError> | |
func runReadAndBlock<T>(f: (Realm) throws -> T) throws -> T | |
func runWriteAndBlock(f: (Realm) throws -> Void) throws -> Void |
This file contains 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 RealmSwift | |
private let RealmSchemaVersion: UInt64 = 1 | |
private let DefaultInMemoryRealmIndentifier = "..............." | |
private func realmfileURL(fileName: String, bundleIdentifier: String) -> NSURL? { | |
#if os(tvOS) | |
let path: NSString? = NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true).first | |
#elseif os(iOS) | |
let path: NSString? = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first |
This file contains 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
@_exported import class Swinject.Container | |
public struct DIContainer { | |
public static let container = Container() | |
private init() { } | |
public static func regist(@noescape block: Container -> Void) { | |
container.removeAll() | |
block(container) |
This file contains 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
public protocol Entity: Equatable { | |
associatedtype ID: Equatable | |
var id: ID { get } | |
} | |
public func ==<E: Entity>(lhs: E, rhs: E) -> Bool { | |
return lhs.id == rhs.id | |
} |
This file contains 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
// 1. インターフェースをつくる | |
protocol UserRepository { | |
func findByID(userID: UserID) -> User | |
} | |
// 2. 実装を作る | |
class UserDAO: UserRepository { | |
init() { ... } |
This file contains 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
func const<A, B>(a: A) -> B -> A { | |
return { _ in a } | |
} |
This file contains 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
protocol OptionalType { | |
associatedtype Wrapped | |
func map<U>(@noescape f: (Wrapped) throws -> U) rethrows -> U? | |
} | |
extension Optional: OptionalType { | |
} | |
extension ObservableType where E: OptionalType { |
This file contains 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
textField.rx_text | |
.map(myMethod) // selfが強参照される → リークする | |
.subscribeNext { _ in } | |
.addDisposableTo(disposeBag) | |
textField.rx_text | |
.map { [unowned self] in self.myMethod($0) } // 長いけどこう書くしかない | |
.subscribeNext { _ in } | |
.addDisposableTo(disposeBag) |
OlderNewer