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
try await withThrowingTaskGroup(of: LoginTaskResult.self) { group in | |
group.addTask(operation: fetchLocation) | |
group.addTask(operation: askForUserPermissions) | |
group.addTask(priority: .high) { | |
return .client(try await APIClient.connect()) | |
} | |
var client: APIClient! | |
for try await result in group { | |
if case LoginTaskResult.client(let api) = result { | |
client = api |
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
Task { | |
await withDiscardingTaskGroup { group in | |
for asset in allAssets { | |
group.addTask { | |
asset.load() | |
} | |
} | |
} | |
} |
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
import Foundation | |
@propertyWrapper | |
struct EmptyToNil<WrappedType: Codable & Collection>: Codable { | |
let wrappedValue: WrappedType? | |
init(wrappedValue: WrappedType?) { | |
self.wrappedValue = wrappedValue | |
} |
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 insertionSort(_ array: [Int]) -> [Int] { | |
guard array.count > 1 else { return array } | |
var sorted = array | |
for i in 1..<array.count { | |
let current = sorted[i] | |
var next: Int? | |
for j in 0...i { | |
if next == nil, | |
current < sorted[j] { | |
next = current |
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 selectionSort(_ array: [Int]) -> [Int] { | |
guard array.count > 1 else { return array } | |
var sorted = array | |
var smallestIndex = 0 | |
for i in 0..<array.count { | |
for j in (i + 1)..<array.count { | |
if sorted[j] < sorted[smallestIndex] { | |
smallestIndex = j | |
} | |
} |
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 bubbleSort(_ array: [Int]) -> [Int] { | |
guard array.count > 1 else { return array } | |
var sorted = array | |
var length = array.count | |
while length > 1 { | |
for i in 1..<length { | |
if sorted[i - 1] > sorted[i] { | |
let current = sorted[i] | |
sorted[i] = sorted[i - 1] | |
sorted[i - 1] = current |
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 reverseStringRecursive(_ string: String) -> String { | |
guard !string.isEmpty else { return string } | |
return reverseStringRecursive(String(string.suffix(string.count - 1))) + String(string[string.index(string.startIndex, offsetBy: 0)]) | |
} | |
func reverseStringIterative(_ string: String) -> String { | |
var result = "" | |
for i in (0..<string.count).reversed() { | |
result += String(string[string.index(string.startIndex, offsetBy: i)]) | |
} |
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 fibonacciRecursive(_ index: Int) -> Int { | |
if index < 2 { | |
return index | |
} | |
return fibonacciRecursive(index - 2) + fibonacciRecursive(index - 1) | |
} | |
func fibonacciIterative(_ index: Int) -> Int { | |
if index < 2 { | |
return index |
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 factorialRecursive(_ number: Int) -> Int { | |
if number < 3 { | |
return number | |
} | |
return number * factorialRecursive(number - 1) | |
} | |
func factorialIterative(_ number: Int) -> Int { | |
var result = 1 | |
for i in (2...number) { |
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
class ChatViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
collectionView.transform = CGAffineTransform.reversed | |
// ......... | |
} | |
} |
NewerOlder