This file contains 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 processImageData() async -> Image { | |
let dataResource = await loadWebResource("dataprofile.txt") | |
let imageResource = await loadWebResource("imagedata.dat") | |
let imageTmp = await decodeImage(dataResource, imageResource) | |
let imageResult = await dewarpAndCleanupImage(imageTmp) | |
return imageResult | |
} |
This file contains 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 processImageData(completionBlock: (result: Image) -> Void) { | |
loadWebResource("dataprofile.txt") { dataResource in | |
loadWebResource("imagedata.dat") { imageResource in | |
decodeImage(dataResource, imageResource) { imageTmp in | |
dewarpAndCleanupImage(imageTmp) { imageResult in | |
completionBlock(imageResult) | |
} | |
} | |
} | |
} |
This file contains 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
// Swift 4: 'Int??' | |
// Swift 5: 'Int?' | |
let result = try? database?.countOfRows(matching: predicate) | |
// Swift 4: 'String??' | |
// Swift 5: 'String?' | |
let myString = try? String(data: someData, encoding: .utf8) | |
// Swift 4: '[String: Any]??' |
This file contains 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 d: [String: String?] = ["a": "1", "b": nil, "c": "3"] | |
let r4 = d.compactMapValues({$0}) | |
// r4 == ["a": "1", "c": "3"] |
This file contains 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 d: [String: String?] = ["a": "1", "b": nil, "c": "3"] | |
let r1 = d.filter { $0.value != nil }.mapValues { $0! } | |
let r2 = d.reduce(into: [String: String]()) { (result, item) in result[item.key] = item.value } | |
// r1 == r2 == ["a": "1", "c": "3"] |
This file contains 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
[1, 2, 3, -1, -2].count(where: { $0 > 0 }) // => 3 |
This file contains 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
[1, 2, 3, -1, -2].reduce(0) { $1 > 0 ? $0 + 1 : $0 } |
This file contains 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
[1, 2, 3, -1, -2].lazy.filter({ $0 > 0 }).count // => 3 |
This file contains 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
[1, 2, 3, -1, -2].filter({ $0 > 0 }).count // => 3 |
This file contains 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 swift(<4.2) | |
// This will only be executed if the Swift version is less than 4.2. | |
#endif | |
#if compiler(<4.2) | |
// This will only be executed if the Swift compiler version is less than 4.2. | |
#endif |