Skip to content

Instantly share code, notes, and snippets.

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
}
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))
}
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 {
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))!)})
}
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))!)})
}
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)!)})
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)
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()
let p1 = promise1.then {
...
}
let p2 = promise2.then {
...
}
when(fulfilled: p1, p2).catch { error in
...
login().then { username in
getTokens(for: username).map { ($0, username) }
}.then { tokens, username in
//…
}