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 { | |
var myDogs: [Dog] = [] | |
func fetchMyDogs() { | |
// Faking a network call | |
DispatchQueue.background.async { | |
self.myDogs = [Dog(name: “Charlie”), Dog(name: “Sam”)] | |
} | |
} |
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 sortDogs() { | |
DispatchQueue.main.async { | |
// do a GET on the main thread | |
let unsortedDogs = self.myDogs | |
DispatchQueue.background.async { | |
// sort on the background thread | |
let sortedDogs = unsortedDogs.sorted { $0.name < $1.name } | |
DispatchQueue.main.async { |
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 fetchMyDogs() { | |
// Faking a network call | |
DispatchQueue.background.async { | |
DispatchQueue.main.async { | |
self.myDogs = [Dog(name: “Charlie”), Dog(name: “Sam”)] | |
} | |
} | |
} |
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
-----BEGIN PGP PUBLIC KEY BLOCK----- | |
Version: Mailvelope v0.12.0 | |
Comment: https://www.mailvelope.com | |
xsFNBFUmlvUBEADCx3X1qEY5Ix8KOknVML1S2Ltxf3mKQj8HZ2vzP6RJIpJg | |
MUhl3NOpM/wqDTALTg04G7aTqC7Llr0qSvOI2BJPNizqA+bMLnBSWBXoKMC/ | |
U8EyFuJ92Y5o7pOOHnqcE6/fN+FfF+1+wiafXMm6+6ucUENX9S0U/Hf0ND9p | |
Oxq0HRWCVhEPhLAGKctgpnhl85F8K0wccWh/Tuv8T01BynlwYvJ6nHUfqAwD | |
jGvh0WGrRRaFOsX7mG2T3TkgiIp2Xi1x0WWq2Wyo9AaXrVsy2CJwE1M0Aked | |
SpQ2mgQos3Du0IGVH4sWhrZw4hHd3wLVukjXArrY269ZQ5YPvanxvx8jJltg |
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
typealias EmptyResult = Result<Empty?, Empty?> | |
typealias StandardResult = Result<Empty?, String?> | |
enum Result<T, U> { | |
typealias SuccessType = T | |
typealias FailureType = U | |
case Success(Box<SuccessType>) | |
case Failure(Box<FailureType>) |