Skip to content

Instantly share code, notes, and snippets.

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

Gary Tokman gtokman

🏴‍☠️
Focusing
View GitHub Profile
@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)
@gtokman
gtokman / pizza.json
Last active May 29, 2021 03:49
Pizza Sample
{
"businesses": [
{
"id": "htEuhPBhBgMs6ShlT3G3JA",
"alias": "regina-pizzeria-boston-28",
"name": "Regina Pizzeria",
"image_url": "https://s3-media3.fl.yelpcdn.com/bphoto/rPG03lJzJVlrTJNrQnuQxg/o.jpg",
"is_closed": false,
"url": "https://www.yelp.com/biz/regina-pizzeria-boston-28?adjust_creative=P9N85ndOnt6FtF1FkbyulA&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=P9N85ndOnt6FtF1FkbyulA",
"review_count": 2099,
[
{
"name": "Gary Tokman",
"bio": "iOS dev working with SwiftUI",
"imageUrl": "https://pbs.twimg.com/profile_images/1395577843476742144/MOWWQV-V_400x400.jpg",
"twitter": "f6ary"
},
{
"name": "Elon Musk",
"bio": "CEO of Tesla",
@gtokman
gtokman / ViewController.swift
Last active March 28, 2021 20:27
subscribe vs receive
["hello world"]
.publisher
.subscribe(on: DispatchQueue.global(qos: .background)) // 1
.map { string -> String in
print("Is main thread in map:", Thread.isMainThread)
return string
}
.breakpoint(receiveOutput: { str in
print("current str:", str)
return Thread.isMainThread // if main thread, breakpoint