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
import CoreLocation | |
/// Endpoints for Yelp | |
enum YelpEndpoint { | |
case search(term: String, location: CLLocation) | |
case detail(id: String) | |
} |
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
Task { | |
let (data, _) = try! await session.data(for: request) | |
let result = try! JSONDecoder().decode(SearchResult.self, from: data) | |
self.businesses = result.businesses | |
} |
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
NavigationView { | |
List { | |
ForEach(businesses) { business in | |
Text(business.name) | |
} | |
} | |
.listStyle(.plain) | |
.navigationTitle(Text("Boston")) | |
.refreshable { | |
// do something |
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
NavigationView { | |
List { | |
ForEach(businesses) { business in | |
Text(business.name) | |
} | |
// Swipe actions | |
.swipeActions( | |
edge: .trailing, | |
allowsFullSwipe: true, | |
content: { |
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
@State var businesses = [Bussiness]() | |
NavigationView { | |
List { | |
ForEach(businesses) { business in | |
Text(business.name ?? "no name") | |
} | |
} | |
.listStyle(.plain) | |
.navigationTitle(Text("Boston")) |
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
NavigationView { | |
List { | |
ForEach(businesses) { business in | |
Text(business.name) | |
} | |
} | |
.listStyle(.plain) | |
.navigationTitle(Text("Boston")) | |
.searchable($searchText) | |
// Receive an update here when the user selects the done button on the keyboard |
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
NavigationView { | |
List { | |
ForEach(viewModel.businesses) { business in | |
Text(business.name) | |
} | |
} | |
.listStyle(.plain) | |
.navigationTitle(Text("Boston")) | |
// Position a gradient at the bottom edge of a list | |
.safeAreaInset(edge: .bottom) { |
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
NavigationView { | |
List { | |
ForEach(businesses, id: \.id) { business in | |
Text(business.name) | |
} | |
} | |
.listStyle(.plain) | |
.navigationTitle(Text("Boston")) | |
// New tool bar modifier and tool bar item | |
.toolbar { |
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
NavigationView { | |
List { | |
ForEach(businesses, id: \.id) { business in | |
Text(business.name) | |
} | |
} | |
.listStyle(.plain) | |
.navigationTitle(Text("Restaurant")) | |
// Add the new searchable modifier on List | |
.searchable(text: $searchText) { |
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
// Grab everything before the cursor | |
var before = textDocumentProxy.documentContextBeforeInput | |
var completePriorString = "" | |
while let beforeInput = before, !beforeInput.isEmpty { | |
completePriorString = beforeInput | |
let length = beforeInput.lengthOfBytes(using: String.Encoding.utf8) | |
textDocumentProxy.adjustTextPosition(byCharacterOffset: -length) |