Skip to content

Instantly share code, notes, and snippets.

View StewartLynch's full-sized avatar

Stewart Lynch StewartLynch

View GitHub Profile
import SwiftUI
enum Style: String, CaseIterable {
case grouped, inset, insetGrouped, plain, sidebar
}
struct ContentView: View {
@State private var selectedStyle: Style = .plain
var body: some View {
@StewartLynch
StewartLynch / PrintDetail
Created November 6, 2022 22:20
Print file, function and line along with the printed items
public func printDetail( _ items: Any...,
fileID: String = #fileID,
function: String = #function,
line: Int = #line,
separator: String = " ",
terminator: String = "\n") {
print("___________________________")
print(items.map{ "\($0)" }.joined(separator: separator))
print(
"""
// How can I transition from the sidebar view to the contentView on iPhone?
import SwiftUI
struct Name: Identifiable, Hashable {
let id = UUID()
var firstName: String
var lastName: String
static var sample: [Name] {
//
// Created for ErrorAlert
// by Stewart Lynch on 2022-06-22
// Using Swift 5.0
//
// Follow me on Twitter: @StewartLynch
// Subscribe on YouTube: https://youTube.com/StewartLynch
//
import SwiftUI
// is there a better way to do this?
// I want to be able to execute something after all of the items have printed
func doIt() {
let numItems = 3
for item in 0...numItems {
DispatchQueue.main.asyncAfter(deadline: .now() + (Double(item) * 1)) {
print(item)
}
}
extension Bundle {
public func decode<T: Decodable>(_ type: T.Type,
from file: String,
dateDecodingStategy: JSONDecoder.DateDecodingStrategy = .deferredToDate,
keyDecodingStrategy: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys) -> T {
guard let url = self.url(forResource: file, withExtension: nil) else {
fatalError("Failed to locate \(file) in bundle.")
}
guard let data = try? Data(contentsOf: url) else {
fatalError("Failed to load \(file) from bundle.")
struct ContentView: View {
@State private var names = ["Stewart", "Emily"]
@State private var newName = ""
@FocusState private var isFosused:Bool
var body: some View {
NavigationView {
List() {
ForEach($names, id:\.self) { $name in
TextField(name, text: $name)
.focused($isFosused, equals: true)
//
// Country.swift
// Country
//
// Created by Stewart Lynch on 2021-07-16.
//
import Foundation
struct Country: Identifiable {
class APIService {
static let shared = APIService()
enum APIError: Error {
case error(_ errorString: String)
}
func getJSON<T: Decodable>(urlString: String,
dateDecodingStrategy: JSONDecoder.DateDecodingStrategy = .deferredToDate,
keyDecodingStrategy: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys,
completion: @escaping (Result<T,APIError>) -> Void) {
//
// ContentView.swift
// OverlayDrag
//
// Created by Stewart Lynch on 2021-07-08.
//
import SwiftUI
struct ContentView: View {