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
extension RawRepresentable { | |
init?(value: Self.RawValue?) { | |
if let value = value { | |
self.init(rawValue: value) | |
} | |
else { | |
return nil | |
} | |
} | |
} |
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
class Base: NSObject, NSCoding, StaticMappable { | |
var d: Int? | |
override init() {} | |
init(d: Int?) { | |
self.d = d | |
} | |
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
extension ObservableType { | |
func flatMap<A: AnyObject, O: ObservableType>(weak obj: A, selector: @escaping (A, Self.E) throws -> O) -> Observable<O.E> { | |
return flatMap { [weak obj] value -> Observable<O.E> in | |
try obj.map { try selector($0, value).asObservable() } ?? .empty() | |
} | |
} | |
func flatMapFirst<A: AnyObject, O: ObservableType>(weak obj: A, selector: @escaping (A, Self.E) throws -> O) -> Observable<O.E> { | |
return flatMapFirst { [weak obj] value -> Observable<O.E> in |
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
login(username: "Username", password: "Password") | |
.flatMap { [weak self] user -> Observable<[Post]> in | |
return self.loadPosts(for: user) | |
} | |
.subscribe() |
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
login(username: "Username", password: "Password") | |
.flatMap { [weak self] user -> Observable<[Post]> in | |
guard let `self` = self else { | |
return Observable.empty() | |
} | |
return self.loadPosts(for: user) | |
} | |
.subscribe() |
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
extension ObservableType { | |
func flatMap<A: AnyObject, O: ObservableType>(weak obj: A, selector: @escaping (A, Self.E) throws -> O) -> Observable<O.E> { | |
return flatMap { [weak obj] value -> Observable<O.E> in | |
try obj.map { try selector($0, value).asObservable() } ?? .empty() | |
} | |
} | |
} |
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
login(username: "Username", password: "Password") | |
.flatMap(weak: self) { obj, user -> Observable<[Post]> in | |
return obj.loadPosts(for: user) | |
} | |
.subscribe() |
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
osx_image: xcode8.3 | |
xcode_workspace: HelloOpenSource.xcworkspace | |
matrix: | |
include: | |
- os: linux | |
dist: trusty | |
sudo: required | |
language: generic | |
- xcode_scheme: HelloOpenSource macOS |
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 HasService1 { | |
var service1: Service1 { get } | |
} | |
protocol HasService2 { | |
var service2: Service2 { get } | |
} | |
class Service1 {} | |
class Service2 {} |
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
static public func create() -> Disposable { | |
return NopDisposable.noOp | |
} |
OlderNewer