Skip to content

Instantly share code, notes, and snippets.

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

Gary Tokman gtokman

🏴‍☠️
Focusing
View GitHub Profile
import Foundation
import CoreData
class CoreDataStack {
let modelName = "Data Model Name"
private lazy var applicationDocumentsDirectory: NSURL = {
let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
import UIKit
protocol PostGateway {
func getPosts(completion: (String) -> Void)
}
protocol getPosts {
func addPost(postID: String)
func removePost(postID: String)
func comment()
import UIKit
// If you enjoyed this talk (video link will be up soon), then you might also enjoy our book Advanced Swift: http://www.objc.io/books/advanced-swift
struct Person {
let name: String
let city: String
}
let people = [
# Given a String
example_string = "Hello Welcome to New York City"
def find_capitals(words):
capitals = list()
for letter in list(words):
# Determine the letters that are capital case
if letter.isupper():
# put them into an array
@gtokman
gtokman / WeatherService.swift
Last active January 28, 2021 22:04
WeatherApp Debug
func fetchForecast(for location: CLLocation) -> AnyPublisher<API, Error> {
// before
let started = Date()
var components = URLComponents()
components.path = "/data/2.5/onecall"
components.queryItems = [
"lat": String(location.coordinate.latitude),
"lon": String(location.coordinate.longitude),
"units": "imperial",
"appid": "",
@gtokman
gtokman / CardView.swift
Last active February 21, 2021 04:09
tc-6
// 1
.rotationEffect(.degrees(degrees))
@gtokman
gtokman / swiftgen-custom.stencil
Created March 3, 2021 02:59
swift gen swiftui stencil
// swiftlint:disable all
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
{% if catalogs %}
{% set enumName %}{{param.enumName|default:"Asset"}}{% endset %}
{% set colorType %}{{param.colorTypeName|default:"ColorAsset"}}{% endset %}
{% set imageType %}{{param.imageTypeName|default:"ImageAsset"}}{% endset %}
{% set forceNamespaces %}{{param.forceProvidesNamespaces|default:"false"}}{% endset %}
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
import SwiftUI
@gtokman
gtokman / TabViewPage.swift
Created March 10, 2021 04:44
PageTabViewStyle
struct ContentView: View {
let colors: [Color] = [
.red, .green, .blue, .gray
]
var body: some View {
GeometryReader { proxy in
TabView {
ForEach(colors, id: \.self) { color in
color // Your cell content
@gtokman
gtokman / TabViewPage.swift
Last active March 10, 2021 04:53
Vertical paging with TabView
struct ContentView: View {
let colors: [Color] = [
.red, .green, .blue, .gray
]
var body: some View {
GeometryReader { proxy in
TabView {
ForEach(colors, id: \.self) { color in
color // Your cell content
func search(needle: String, haystack: String) -> Bool {
guard needle.count <= haystack.count else {
return false
}
if needle == haystack {
return true
}
var needleIdx = needle.startIndex