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
struct ContentView: View { | |
var body: some View { | |
VStack { | |
Button("Async") { | |
Task { | |
await asyncFunction() | |
} | |
} | |
} | |
} |
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
struct ContentView: View { | |
@State var taskTrigger: Bool = false | |
var body: some View { | |
Button("Execute Task", action: { | |
taskTrigger.toggle() | |
}).task(id: taskTrigger) { | |
do { | |
let newText = try await getText() | |
print(newText) | |
} catch { |
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
@main | |
struct MainApp { | |
static func main() async { | |
await asyncFunction() | |
} | |
} |
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 getUserData(for id: Int) async throws -> Family { | |
let user = try await getUser(id: id) | |
let parents = try await getParents(of: user) | |
return createFamily(user, parent) | |
} |
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
struct SomeView { | |
var data: Data? { | |
get async throws { | |
return await fetchData() | |
} | |
} | |
func fetchData() async throws -> Data? { | |
// .... | |
} |
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 UIKit | |
enum Section { | |
case section1 | |
case section2 | |
} | |
struct Item: Hashable { | |
let color: UIColor | |
} |
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
extension ViewController { | |
func addItems(items: [Item], to section: Section) { | |
var snapshot = dataSource.snapshot() | |
snapshot.appendSections([section]) | |
snapshot.appendItems(items, toSection: section) | |
dataSource.apply(snapshot) | |
} | |
} |
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 ViewController: UIViewController { | |
@IBOutlet var collectionview: UICollectionView! | |
lazy var dataSource = UICollectionViewDiffableDataSource<Section, Item>(collectionView: self.collectionview, | |
cellProvider: self.cellProvider) | |
lazy var cellProvider: (UICollectionView, IndexPath, Item) -> UICollectionViewCell? = { collectionView, indexPath, item in | |
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) | |
cell.backgroundColor = item.color | |
return cell | |
} | |
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 ViewController: UIViewController { | |
@IBOutlet var collectionview: UICollectionView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} | |
} |
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
enum Section { | |
case section1 | |
case section2 | |
} | |
struct Item: Hashable { | |
let name: String | |
} |