Fixes RxExample.

This commit is contained in:
Mo Ramezanpoor 2016-08-17 09:49:29 +01:00
parent b9b593d740
commit 0fe4c9a792
16 changed files with 72 additions and 71 deletions

View File

@ -18,17 +18,17 @@ extension UITableView {
public func rx_itemsAnimatedWithDataSource<
DataSource: RxTableViewDataSourceType & UITableViewDataSource,
S: Sequence,
O: ObservableType
where
DataSource.Element == S,
O.E == S,
S.Iterator.Element: AnimatableSectionModelType
>
O: ObservableType>
(_ dataSource: DataSource)
-> (source: O)
-> Disposable {
-> (_ source: O)
-> Disposable
where
DataSource.Element == S,
O.E == S,
S.Iterator.Element: AnimatableSectionModelType
{
return { source in
return self.rx_itemsWithDataSource(dataSource)(source: source)
return self.rx_itemsWithDataSource(dataSource)(source)
}
}
}
@ -38,17 +38,17 @@ extension UICollectionView {
public func rx_itemsAnimatedWithDataSource<
DataSource: RxCollectionViewDataSourceType & UICollectionViewDataSource,
S: Sequence,
O: ObservableType
where
DataSource.Element == S,
O.E == S,
S.Iterator.Element: AnimatableSectionModelType
>
O: ObservableType>
(_ dataSource: DataSource)
-> (source: O)
-> Disposable {
-> (_ source: O)
-> Disposable
where
DataSource.Element == S,
O.E == S,
S.Iterator.Element: AnimatableSectionModelType
{
return { source in
return self.rx_itemsWithDataSource(dataSource)(source: source)
return self.rx_itemsWithDataSource(dataSource)(source)
}
}
}

View File

@ -142,14 +142,14 @@ public class CollectionViewSectionedDataSource<S: SectionModelType>
}
}
public var moveItem: ((CollectionViewSectionedDataSource<S>, sourceIndexPath:IndexPath, destinationIndexPath:IndexPath) -> Void)? {
public var moveItem: ((CollectionViewSectionedDataSource<S>, _ sourceIndexPath:IndexPath, _ destinationIndexPath:IndexPath) -> Void)? {
didSet {
#if DEBUG
ensureNotMutatedAfterBinding()
#endif
}
}
public var canMoveItemAtIndexPath: ((CollectionViewSectionedDataSource<S>, indexPath:IndexPath) -> Bool)? {
public var canMoveItemAtIndexPath: ((CollectionViewSectionedDataSource<S>, IndexPath) -> Bool)? {
didSet {
#if DEBUG
ensureNotMutatedAfterBinding()
@ -196,7 +196,7 @@ public class CollectionViewSectionedDataSource<S: SectionModelType>
}
override func _rx_collectionView(_ collectionView: UICollectionView, canMoveItemAtIndexPath indexPath: IndexPath) -> Bool {
guard let canMoveItem = canMoveItemAtIndexPath?(self, indexPath: indexPath) else {
guard let canMoveItem = canMoveItemAtIndexPath?(self, indexPath) else {
return super._rx_collectionView(collectionView, canMoveItemAtIndexPath: indexPath)
}

View File

@ -165,14 +165,14 @@ public class RxTableViewSectionedDataSource<S: SectionModelType>
}
}
public var titleForHeaderInSection: ((RxTableViewSectionedDataSource<S>, section: Int) -> String?)? {
public var titleForHeaderInSection: ((RxTableViewSectionedDataSource<S>, Int) -> String?)? {
didSet {
#if DEBUG
ensureNotMutatedAfterBinding()
#endif
}
}
public var titleForFooterInSection: ((RxTableViewSectionedDataSource<S>, section: Int) -> String?)? {
public var titleForFooterInSection: ((RxTableViewSectionedDataSource<S>, Int) -> String?)? {
didSet {
#if DEBUG
ensureNotMutatedAfterBinding()
@ -180,14 +180,14 @@ public class RxTableViewSectionedDataSource<S: SectionModelType>
}
}
public var canEditRowAtIndexPath: ((RxTableViewSectionedDataSource<S>, indexPath: IndexPath) -> Bool)? {
public var canEditRowAtIndexPath: ((RxTableViewSectionedDataSource<S>, IndexPath) -> Bool)? {
didSet {
#if DEBUG
ensureNotMutatedAfterBinding()
#endif
}
}
public var canMoveRowAtIndexPath: ((RxTableViewSectionedDataSource<S>, indexPath: IndexPath) -> Bool)? {
public var canMoveRowAtIndexPath: ((RxTableViewSectionedDataSource<S>, IndexPath) -> Bool)? {
didSet {
#if DEBUG
ensureNotMutatedAfterBinding()
@ -205,7 +205,7 @@ public class RxTableViewSectionedDataSource<S: SectionModelType>
#endif
}
}
public var sectionForSectionIndexTitle:((RxTableViewSectionedDataSource<S>, title: String, index: Int) -> Int)? {
public var sectionForSectionIndexTitle:((RxTableViewSectionedDataSource<S>, _ title: String, _ index: Int) -> Int)? {
didSet {
#if DEBUG
ensureNotMutatedAfterBinding()
@ -242,15 +242,15 @@ public class RxTableViewSectionedDataSource<S: SectionModelType>
}
override func _rx_tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return titleForHeaderInSection?(self, section: section)
return titleForHeaderInSection?(self, section)
}
override func _rx_tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
return titleForFooterInSection?(self, section: section)
return titleForFooterInSection?(self, section)
}
override func _rx_tableView(_ tableView: UITableView, canEditRowAtIndexPath indexPath: IndexPath) -> Bool {
guard let canEditRow = canEditRowAtIndexPath?(self, indexPath: indexPath) else {
guard let canEditRow = canEditRowAtIndexPath?(self, indexPath) else {
return super._rx_tableView(tableView, canEditRowAtIndexPath: indexPath)
}
@ -258,7 +258,7 @@ public class RxTableViewSectionedDataSource<S: SectionModelType>
}
override func _rx_tableView(_ tableView: UITableView, canMoveRowAtIndexPath indexPath: IndexPath) -> Bool {
guard let canMoveRow = canMoveRowAtIndexPath?(self, indexPath: indexPath) else {
guard let canMoveRow = canMoveRowAtIndexPath?(self, indexPath) else {
return super._rx_tableView(tableView, canMoveRowAtIndexPath: indexPath)
}
@ -279,7 +279,7 @@ public class RxTableViewSectionedDataSource<S: SectionModelType>
}
override func _rx_tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int {
guard let section = sectionForSectionIndexTitle?(self, title: title, index: index) else {
guard let section = sectionForSectionIndexTitle?(self, title, index) else {
return super._rx_tableView(tableView, sectionForSectionIndexTitle: title, atIndex: index)
}

View File

@ -14,7 +14,7 @@ import RxCocoa
#endif
extension UILabel {
public override var accessibilityValue: String! {
open override var accessibilityValue: String! {
get {
return self.text
}

View File

@ -102,7 +102,7 @@ class GitHubSearchRepositoriesAPI {
// Do we really want to make this example project factory/fascade/service competition? :)
private let _wireframe: Wireframe
private let _reachabilityService: ReachabilityService
fileprivate let _reachabilityService: ReachabilityService
private init(wireframe: Wireframe, reachabilityService: ReachabilityService) {
_wireframe = wireframe
@ -197,7 +197,7 @@ extension GitHubSearchRepositoriesAPI {
private static let parseLinksPattern = "\\s*,?\\s*<([^\\>]*)>\\s*;\\s*rel=\"([^\"]*)\""
private static let linksRegex = try! NSRegularExpression(pattern: parseLinksPattern, options: [.allowCommentsAndWhitespace])
private static func parseLinks(_ links: String) throws -> [String: String] {
fileprivate static func parseLinks(_ links: String) throws -> [String: String] {
let length = (links as NSString).length
let matches = GitHubSearchRepositoriesAPI.linksRegex.matches(in: links, options: NSRegularExpression.MatchingOptions(), range: NSRange(location: 0, length: length))
@ -223,7 +223,7 @@ extension GitHubSearchRepositoriesAPI {
return result
}
private static func parseNextURL(_ httpResponse: HTTPURLResponse) throws -> URL? {
fileprivate static func parseNextURL(_ httpResponse: HTTPURLResponse) throws -> URL? {
guard let serializedLinks = httpResponse.allHeaderFields["Link"] as? String else {
return nil
}
@ -241,15 +241,15 @@ extension GitHubSearchRepositoriesAPI {
return nextUrl
}
private static func parseJSON(_ httpResponse: HTTPURLResponse, data: Data) throws -> AnyObject {
fileprivate static func parseJSON(_ httpResponse: HTTPURLResponse, data: Data) throws -> AnyObject {
if !(200 ..< 300 ~= httpResponse.statusCode) {
throw exampleError("Call failed")
}
return try JSONSerialization.jsonObject(with: data ?? Data(), options: [])
return try JSONSerialization.jsonObject(with: data, options: []) as AnyObject
}
private static func parseRepositories(_ json: [String: AnyObject]) throws -> [Repository] {
fileprivate static func parseRepositories(_ json: [String: AnyObject]) throws -> [Repository] {
guard let items = json["items"] as? [[String: AnyObject]] else {
throw exampleError("Can't find items")
}

View File

@ -23,8 +23,7 @@ extension UINavigationController {
return UIBindingObserver(UIElement: self) { navigationController, maybeServiceState in
// if nil is being bound, then don't change color, it's not perfect, but :)
if let serviceState = maybeServiceState {
let safeState = (serviceState ?? .online)
let isOffline = safeState == .offline
let isOffline = serviceState == .offline
self.navigationBar.backgroundColor = isOffline
? Colors.OfflineColor

View File

@ -28,7 +28,7 @@ func dismissViewController(_ viewController: UIViewController, animated: Bool) {
}
extension UIImagePickerController {
static func rx_createWithParent(_ parent: UIViewController?, animated: Bool = true, configureImagePicker: (UIImagePickerController) throws -> () = { x in }) -> Observable<UIImagePickerController> {
static func rx_createWithParent(_ parent: UIViewController?, animated: Bool = true, configureImagePicker: @escaping (UIImagePickerController) throws -> () = { x in }) -> Observable<UIImagePickerController> {
return Observable.create { [weak parent] observer in
let imagePicker = UIImagePickerController()
let dismissDisposable = imagePicker

View File

@ -70,7 +70,7 @@ class SimpleTableViewExampleSectionedViewController
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let label = UILabel(frame: CGRect.zero)
label.text = dataSource.sectionAtIndex(section).model ?? ""
label.text = dataSource.sectionAtIndex(section).model
return label
}
}

View File

@ -60,7 +60,7 @@ class SearchResultViewModel {
.observeOn($.backgroundWorkScheduler)
.map { page in
do {
return try parseImageURLsfromHTMLSuitableForDisplay(page.text)
return try parseImageURLsfromHTMLSuitableForDisplay(page.text as NSString)
} catch {
return []
}

View File

@ -38,7 +38,7 @@ public class WikipediaSearchCell: UITableViewCell {
.drive(self.titleOutlet.rx_text)
.addDisposableTo(disposeBag)
self.URLOutlet.text = viewModel.searchResult.URL.absoluteString ?? ""
self.URLOutlet.text = viewModel.searchResult.URL.absoluteString
let reachabilityService = Dependencies.sharedDependencies.reachabilityService
viewModel.imageURLs

View File

@ -22,8 +22,11 @@ struct WikipediaPage {
// tedious parsing part
static func parseJSON(_ json: NSDictionary) throws -> WikipediaPage {
guard let title = json.value(forKey: "parse")?.value(forKey: "title") as? String,
let text = json.value(forKey: "parse")?.value(forKey: "text")?.value(forKey: "*") as? String else {
guard
let parse = json.value(forKey: "parse"),
let title = (parse as AnyObject).value(forKey: "title") as? String,
let t = (parse as AnyObject).value(forKey: "text"),
let text = (t as AnyObject).value(forKey: "*") as? String else {
throw apiError("Error parsing page content")
}

View File

@ -16,8 +16,7 @@ import UIKit
// Two way binding operator between control property and variable, that's all it takes {
infix operator <-> {
}
infix operator <-> : DefaultPrecedence
func nonMarkedText(_ textInput: UITextInput) -> String? {
let start = textInput.beginningOfDocument

View File

@ -16,7 +16,7 @@ private struct ActivityToken<E> : ObservableConvertibleType, Disposable {
private let _source: Observable<E>
private let _dispose: Cancelable
init(source: Observable<E>, disposeAction: () -> ()) {
init(source: Observable<E>, disposeAction: @escaping () -> ()) {
_source = source
_dispose = Disposables.create(with: disposeAction)
}
@ -49,7 +49,7 @@ public class ActivityIndicator : DriverConvertibleType {
.distinctUntilChanged()
}
private func trackActivityOfObservable<O: ObservableConvertibleType>(_ source: O) -> Observable<O.E> {
fileprivate func trackActivityOfObservable<O: ObservableConvertibleType>(_ source: O) -> Observable<O.E> {
return Observable.using({ () -> ActivityToken<O.E> in
self.increment()
return ActivityToken(source: source.asObservable(), disposeAction: self.decrement)

View File

@ -57,7 +57,7 @@ class DefaultImageService: ImageService {
private func _imageFromURL(_ url: URL) -> Observable<Image> {
return Observable.deferred {
let maybeImage = self._imageCache.object(forKey: url) as? Image
let maybeImage = self._imageCache.object(forKey: url as AnyObject) as? Image
let decodedImage: Observable<Image>
@ -66,7 +66,7 @@ class DefaultImageService: ImageService {
decodedImage = Observable.just(image)
}
else {
let cachedData = self._imageDataCache.object(forKey: url) as? Data
let cachedData = self._imageDataCache.object(forKey: url as AnyObject) as? Data
// does image data cache contain anything
if let cachedData = cachedData {
@ -76,7 +76,7 @@ class DefaultImageService: ImageService {
// fetch from network
decodedImage = self.$.URLSession.rx_data(URLRequest(url: url))
.do(onNext: { data in
self._imageDataCache.setObject(data, forKey: url)
self._imageDataCache.setObject(data as AnyObject, forKey: url as AnyObject)
})
.flatMap(self.decodeImage)
.trackActivity(self.loadingImage)
@ -84,7 +84,7 @@ class DefaultImageService: ImageService {
}
return decodedImage.do(onNext: { image in
self._imageCache.setObject(image, forKey: url)
self._imageCache.setObject(image, forKey: url as AnyObject)
})
}
}

View File

@ -37,7 +37,7 @@ enum ReachabilityError: Swift.Error {
public let ReachabilityChangedNotification = "ReachabilityChangedNotification"
func callback(_ reachability:SCNetworkReachability, flags: SCNetworkReachabilityFlags, info: UnsafeMutablePointer<Void>?) {
func callback(_ reachability:SCNetworkReachability, flags: SCNetworkReachabilityFlags, info: UnsafeMutableRawPointer?) {
guard let info = info else { return }
let reachability = Unmanaged<Reachability>.fromOpaque(info).takeUnretainedValue()
@ -110,11 +110,13 @@ public class Reachability: NSObject {
public class func reachabilityForInternetConnection() throws -> Reachability {
var zeroAddress = sockaddr_in()
zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress))
zeroAddress.sin_len = UInt8(MemoryLayout<sockaddr_in>.size)
zeroAddress.sin_family = sa_family_t(AF_INET)
guard let ref = withUnsafePointer(&zeroAddress, {
SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0))
guard let ref = withUnsafePointer(to: &zeroAddress, {
$0.withMemoryRebound(to: sockaddr.self, capacity: 1) {
SCNetworkReachabilityCreateWithAddress(nil, $0)
}
}) else { throw ReachabilityError.failedToCreateWithAddress(zeroAddress) }
return Reachability(reachabilityRef: ref)
@ -123,15 +125,17 @@ public class Reachability: NSObject {
public class func reachabilityForLocalWiFi() throws -> Reachability {
var localWifiAddress: sockaddr_in = sockaddr_in(sin_len: __uint8_t(0), sin_family: sa_family_t(0), sin_port: in_port_t(0), sin_addr: in_addr(s_addr: 0), sin_zero: (0, 0, 0, 0, 0, 0, 0, 0))
localWifiAddress.sin_len = UInt8(sizeofValue(localWifiAddress))
localWifiAddress.sin_len = UInt8(MemoryLayout<sockaddr_in>.size)
localWifiAddress.sin_family = sa_family_t(AF_INET)
// IN_LINKLOCALNETNUM is defined in <netinet/in.h> as 169.254.0.0
let address: UInt32 = 0xA9FE0000
localWifiAddress.sin_addr.s_addr = in_addr_t(address.bigEndian)
guard let ref = withUnsafePointer(&localWifiAddress, {
SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0))
guard let ref = withUnsafePointer(to: &localWifiAddress, {
$0.withMemoryRebound(to: sockaddr.self, capacity: 1) {
SCNetworkReachabilityCreateWithAddress(nil, $0)
}
}) else { throw ReachabilityError.failedToCreateWithAddress(localWifiAddress) }
return Reachability(reachabilityRef: ref)
@ -226,7 +230,7 @@ public class Reachability: NSObject {
private var reachabilityRef: SCNetworkReachability?
private let reachabilitySerialQueue = DispatchQueue(label: "uk.co.ashleymills.reachability")
private func reachabilityChanged(_ flags: SCNetworkReachabilityFlags) {
fileprivate func reachabilityChanged(_ flags: SCNetworkReachabilityFlags) {
if isReachableWithFlags(flags) {
if let block = whenReachable {
block(self)
@ -267,8 +271,8 @@ public class Reachability: NSObject {
if let reachabilityRef = reachabilityRef {
var flags = SCNetworkReachabilityFlags(rawValue: 0)
let gotFlags = withUnsafeMutablePointer(&flags) {
SCNetworkReachabilityGetFlags(reachabilityRef, UnsafeMutablePointer($0))
let gotFlags = withUnsafeMutablePointer(to: &flags) {
SCNetworkReachabilityGetFlags(reachabilityRef, $0)
}
if gotFlags {
@ -348,8 +352,8 @@ public class Reachability: NSObject {
if let reachabilityRef = reachabilityRef {
var flags = SCNetworkReachabilityFlags(rawValue: 0)
let gotFlags = withUnsafeMutablePointer(&flags) {
SCNetworkReachabilityGetFlags(reachabilityRef, UnsafeMutablePointer($0))
let gotFlags = withUnsafeMutablePointer(to: &flags) {
SCNetworkReachabilityGetFlags(reachabilityRef, $0)
}
if gotFlags {

View File

@ -12,10 +12,6 @@ import UIKit
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
return true
}
}