Skip to content

Instantly share code, notes, and snippets.

View gtokman's full-sized avatar
🏴‍☠️
Focusing

Gary Tokman gtokman

🏴‍☠️
Focusing
View GitHub Profile
import CoreLocation
/// Endpoints for Yelp
enum YelpEndpoint {
case search(term: String, location: CLLocation)
case detail(id: String)
}
Task {
let (data, _) = try! await session.data(for: request)
let result = try! JSONDecoder().decode(SearchResult.self, from: data)
self.businesses = result.businesses
}
NavigationView {
List {
ForEach(businesses) { business in
Text(business.name)
}
}
.listStyle(.plain)
.navigationTitle(Text("Boston"))
.refreshable {
// do something
@gtokman
gtokman / swipe.swift
Last active September 24, 2021 00:55
NavigationView {
List {
ForEach(businesses) { business in
Text(business.name)
}
// Swipe actions
.swipeActions(
edge: .trailing,
allowsFullSwipe: true,
content: {
@gtokman
gtokman / task.swift
Last active September 24, 2021 01:32
@State var businesses = [Bussiness]()
NavigationView {
List {
ForEach(businesses) { business in
Text(business.name ?? "no name")
}
}
.listStyle(.plain)
.navigationTitle(Text("Boston"))
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
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) {
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 {
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) {
@gtokman
gtokman / Keyboard.swift
Created June 28, 2021 22:20
Get full context
// 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)