This file contains 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 Foundation | |
// Here is the codable model that I am trying to decode the feed into | |
struct Feed: Codable { | |
let items: [Items] | |
let pageInfo: PageInfo | |
let nextPageToken: String? | |
} | |
struct PageInfo: Codable { |
This file contains 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 SwiftUI | |
enum Field { | |
case text1 | |
} | |
struct ContentView: View { | |
// This works fine | |
@State private var showModal = false | |
@State private var text1:String = "" |
This file contains 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
struct ContentView: View { | |
@State private var isPresented = false | |
var body: some View { | |
Button("Show Alert") { | |
isPresented = true | |
} | |
.alert("Alert Title", isPresented: $isPresented) { | |
Button("OK",role: .cancel) {} | |
} message: { | |
Text("Message below Title") |
This file contains 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
// | |
// ContentView.swift | |
// OverlayDrag | |
// | |
// Created by Stewart Lynch on 2021-07-08. | |
// | |
import SwiftUI | |
struct ContentView: View { |
This file contains 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
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) { |
This file contains 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
// | |
// Country.swift | |
// Country | |
// | |
// Created by Stewart Lynch on 2021-07-16. | |
// | |
import Foundation | |
struct Country: Identifiable { |
This file contains 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
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.") |
This file contains 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
// 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) | |
} | |
} |
This file contains 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
// | |
// 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 |