Add Random Contact Option

This commit is contained in:
Kyle Fang
2015-09-16 15:59:14 +08:00
committed by kylefang
parent 5d52909e2d
commit c3efa6a73a
3 changed files with 23 additions and 2 deletions

View File

@@ -5,4 +5,5 @@ pod 'RxSwift', '~> 2.0.0-alpha'
pod 'RxCocoa', '~> 2.0.0-alpha'
pod 'RxBlocking', '~> 2.0.0-alpha'
pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git', :branch => 'xcode7'
pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git', :branch => 'xcode7'
pod 'APAddressBook'

View File

@@ -1,4 +1,7 @@
PODS:
- APAddressBook (0.1.11):
- APAddressBook/Core (= 0.1.11)
- APAddressBook/Core (0.1.11)
- RxBlocking (2.0.0-alpha.2):
- RxSwift (~> 2.0.0-alpha)
- RxCocoa (2.0.0-alpha.2):
@@ -7,6 +10,7 @@ PODS:
- SwiftyJSON (2.2.1)
DEPENDENCIES:
- APAddressBook
- RxBlocking (~> 2.0.0-alpha)
- RxCocoa (~> 2.0.0-alpha)
- RxSwift (~> 2.0.0-alpha)
@@ -23,6 +27,7 @@ CHECKOUT OPTIONS:
:git: https://github.com/SwiftyJSON/SwiftyJSON.git
SPEC CHECKSUMS:
APAddressBook: 2c949367b190a993d2cce769a3b20bce8bcf000c
RxBlocking: 0f0fc3a2a845d5bde0cc9fafa949d3af1b0f491c
RxCocoa: 77f76f7319f725cfb418fcb74388689753cbfac6
RxSwift: 0450126df5f8de3ec7ee789b420d7ba98baea364

View File

@@ -10,6 +10,7 @@ import UIKit
import RxSwift
import RxCocoa
import SwiftyJSON
import APAddressBook
struct Preset {
let name:String
@@ -60,7 +61,21 @@ class PresetViewController: UITableViewController {
self.tableView.delegate = nil
self.tableView.dataSource = nil
let contactPreset = Preset(name: "Contacts", hint: "Choose", candidate: [], skipWinner: true, autoRestart: true)
var contactPreset = Preset(name: "Contacts", hint: "Choose", candidate: [], skipWinner: true, autoRestart: true)
contactPreset.prerender = create({ subscribe -> Disposable in
APAddressBook().loadContacts({ (contacts, error) -> Void in
if error != nil {
subscribe.on(Event.Error(NSError(domain: "System", code: 403, userInfo: [NSLocalizedDescriptionKey: "Please allow access in Settings.app"])))
} else {
let candidates = contacts.map({"\($0.firstName) \($0.lastName)"})
subscribe.on(Event.Next(Preset(name: contactPreset.name, hint: contactPreset.hint, candidate: candidates, skipWinner: contactPreset.skipWinner, autoRestart: contactPreset.autoRestart)))
}
})
return AnonymousDisposable {
}
})
let allPresets = just([
SectionModel(model: "", items: [Preset(name: "Tutorial", hint: "Hit it", candidate: ["Shake", "Pinch", "Hold"], skipWinner: true, autoRestart: true)]),