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
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
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 confirm(intent: DanceIntent, completion: @escaping (DanceIntentResponse) -> Void) { | |
// Do Stuff | |
completion(DanceIntentResponse(code: .play, userActivity: nil)) | |
} | |
public func handle(intent: DanceIntent, completion: @escaping (DanceIntentResponse) -> Void) { | |
// Do Stuff | |
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
if let shortcut = voiceShortcutDataManager?.voiceShortcut(for: order) { | |
let editVoiceShortcutViewController = INUIEditVoiceShortcutViewController(voiceShortcut: shortcut) | |
editVoiceShortcutViewController.delegate = self | |
present(editVoiceShortcutViewController, animated: true, completion: nil) | |
} | |
else { | |
if let shortcut = INShortcut(intent: order.intent) { | |
let addVoiceShortcutVC = INUIAddVoiceShortcutViewController(shortcut: shortcut) | |
addVoiceShortcutVC.delegate = self | |
present(addVoiceShortcutVC, animated: true, completion: nil) |
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
var messages: [Message] = [] | |
func dispatch(_ message: Message) { | |
messages.append(message) | |
dispatchToPlugins() | |
} | |
func dispatchToPlugins() { | |
while messages.count > 0 { | |
for plugin in plugins { |
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 write(_ text: String) { | |
let words = text.split(separator: " ") | |
for word in words { | |
title.append(String(word)) | |
} | |
} | |
write("Concurrency with Swift:") // Thread 1 | |
write("What could possibly go wrong?") // Thread 2 |
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
var title : [String] = [] | |
var lock = NSLock() | |
func write(_ text: String) { | |
let words = text.split(separator: " ") | |
lock.lock() | |
for word in words { | |
title.append(String(word)) | |
print(word) | |
} |
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
var title : [String] = [] | |
func write(_ text: String) { | |
let words = text.split(separator: " ") | |
DispatchQueue.main.async { | |
for word in words { | |
title.append(String(word)) | |
print(word) | |
} | |
} |
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
var x = 100 | |
func calculate() { | |
var y = 0 | |
for i in 1...1000 { | |
y += i | |
} | |
x = y | |
} |