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
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { | |
if let intent = userActivity.interaction?.intent as? DanceIntent { | |
handle(intent) | |
return true | |
} | |
return false | |
} |
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
public func handle(intent: DanceIntent, completion: @escaping (DanceIntentResponse) -> Void) { | |
// check for your intent here and handle it accordingly | |
let dance = intent.dance | |
// finish by providing a response | |
completion(DanceIntentResponse.success(dance: dance, playTime: 10)) | |
} |
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 danceIntent = DanceIntent() | |
danceIntent.<property> = //set here your configuration for this intent | |
let interaction = INInteraction(intent: danceIntent, response: nil) | |
interaction.donate { (error) in | |
if error != nil { | |
if let error = error as NSError? { | |
print("error") | |
} | |
} else { |
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
func rotFinal(msg: String, key: String, op: (UInt32, UInt32) -> UInt32) -> String { | |
return String(zip(msg.unicodeScalars.map{$0.value}, String(repeating: key, count: (msg.count / key.count) + 1) | |
.unicodeScalars.map{$0.value}) | |
.map{Character(UnicodeScalar(op($0.0, $0.1))!)}) | |
} |
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
func rot3(msg: String, op: (UInt32, UInt32) -> UInt32) -> String { | |
let numbers = msg.unicodeScalars.map{$0.value} | |
return String(numbers.map{Character(UnicodeScalar(op($0, 3))!)}) | |
} |
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
et number = UInt32(Calendar.current.component(.weekday, from: Date())) | |
let msg = ["D", "(", "o", "o", "#", "(", "w", "k", "h", "#", "e", "(", "h", "v", "w", "!", "(", "#", "d", "q", "(", "g", "#", "n", "h", "h", ")", "s", "#", "r", "!", "q", "#", "h", "y", "d", "!", "o", "x", "d", "w", "(", "l", "q", "j"] | |
print(msg.filter{$0.unicodeScalars.map{$0.value}.reduce(0, +) > 64 | |
|| $0.unicodeScalars.map{$0.value}.reduce(0, +) == 35}.map{ | |
Character(UnicodeScalar($0.unicodeScalars.map{$0.value}.reduce(0, +) | |
- number)!)}) |
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
class ViewController: UIViewController { | |
private let (promise, seal) = Guarantee<...>.pending() | |
func show(in: UIViewController) -> Promise<…> { | |
in.show(self, sender: in) | |
return promise | |
} | |
func done() { | |
dismiss(animated: true) |
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
func foo() -> (Promise<Void>, cancel: () -> Void) { | |
let task = Task(…) | |
var cancelme = false | |
let promise = Promise<Void> { seal in | |
task.completion = { value in | |
guard !cancelme else { reject(NSError.cancelledError) } | |
seal.fulfill(value) | |
} | |
task.start() |
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 p1 = promise1.then { | |
... | |
} | |
let p2 = promise2.then { | |
... | |
} | |
when(fulfilled: p1, p2).catch { error in | |
... |
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
login().then { username in | |
getTokens(for: username).map { ($0, username) } | |
}.then { tokens, username in | |
//… | |
} |