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 | |
struct ContentView: View { | |
@State private var exercises: [Exercise] = Exercise.sample | |
var body: some View { | |
NavigationSplitView(sidebar: { | |
ExercisesList(exercises: exercises) | |
}, detail: { | |
ExerciseDetail(exercise: exercises.first!) | |
}) |
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 UIKit | |
import SwiftUI | |
// Hacky workaround, use at your own risk and all that | |
struct BottomSheetPresenter<Content>: UIViewRepresentable where Content: View{ | |
let label: String | |
let content: Content | |
let detents: [UISheetPresentationController.Detent] | |
init(_ label: String, detents: [UISheetPresentationController.Detent], @ViewBuilder content: () -> Content) { |
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
enum Status: Decodable { | |
case completed, inProgress | |
case other(String) | |
init(from decoder: Decoder) throws { | |
let container = try decoder.singleValueContainer() | |
let value = try container.decode(String.self) | |
switch value { | |
case "completed": self = .completed |
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 | |
enum TargetEnum: Codable { | |
case first(SomeObject) | |
case second(OtherObject) | |
enum CodingKeys: CodingKey { | |
case type | |
} |
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 | |
let json = """ | |
{ | |
"userId": 0, | |
"name": "Donny" | |
} | |
""".data(using: .utf8)! | |
let fakeSQLite = """ |
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 | |
let json = """ | |
{ | |
"userId": 0, | |
"name": "Donny" | |
} | |
""".data(using: .utf8)! | |
struct User: 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
#!/bin/sh | |
# make sure you have imagemagick installed: brew install imagemagick | |
# your app_icons.sh file should have the correct permissions: run `chmod 775 app_icons.sh` in your terminal from where you put this file | |
# put your `my_icon.png` next to this file and run ./app_icons.sh to export your app icons | |
x=my_icon.png | |
y=${x%.*} | |
# delete the export directory so we start clean |
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
/* | |
Here's our goal: | |
let localDataStore = UserDataStore() | |
let remoteDataStore = UserApi() | |
let dataStore = CacheBackedDataStore(localDataStore, remoteDataStore) | |
dataStore.fetch(userID) { result in | |
// handle result | |
} |
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 UploadTaskPublisher { | |
typealias UploadProgress = (bytesSent: Int64, expectedTotalBytes: Int64) | |
typealias ProgressSubject = CurrentValueSubject<UploadProgress, Never> | |
typealias CompletionSubject = PassthroughSubject<URLSession.DataTaskPublisher.Output, URLSession.DataTaskPublisher.Failure> | |
var progress = ProgressSubject((0, 0)) | |
var completion = CompletionSubject() | |
} |
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 | |
@propertyWrapper | |
struct YMD { | |
var wrappedValue: Date? | |
} | |
extension YMD: Codable { | |
func encode(to encoder: Encoder) throws { | |
if let date = self.wrappedValue { |
NewerOlder