Skip to content

Instantly share code, notes, and snippets.

View donnywals's full-sized avatar

Donny Wals donnywals

View GitHub Profile
View BottomSheetWithDetentsSwiftUI.swift
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) {
View UnkownEnumCase.swift
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
View Associated.swift
import Foundation
enum TargetEnum: Codable {
case first(SomeObject)
case second(OtherObject)
enum CodingKeys: CodingKey {
case type
View different-decoding.swift
import Foundation
let json = """
"userId": 0,
"name": "Donny"
""".data(using: .utf8)!
let fakeSQLite = """
View non-matching-keys.swift
import Foundation
let json = """
"userId": 0,
"name": "Donny"
""".data(using: .utf8)!
struct User: Codable {
# make sure you have imagemagick installed: brew install imagemagick
# your file should have the correct permissions: run `chmod 775` in your terminal from where you put this file
# put your `my_icon.png` next to this file and run ./ to export your app icons
# delete the export directory so we start clean
View generics.swift
Here's our goal:
let localDataStore = UserDataStore()
let remoteDataStore = UserApi()
let dataStore = CacheBackedDataStore(localDataStore, remoteDataStore)
dataStore.fetch(userID) { result in
// handle result
View simple_wrapper.swift
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()
View ymd.swift
import Foundation
struct YMD {
var wrappedValue: Date?
extension YMD: Codable {
func encode(to encoder: Encoder) throws {
if let date = self.wrappedValue {

Core Location

  • When an app needs always authorization, they will not receive this authorization immediately
  • Apps that request always authorization receive provisional access, meaning that the user allows when in use access but the app thinks it has always access.
  • An app can then begin doing what they must do in the background and when the time is right, iOS will prompt the user for always access and the app will then receive the "real" status (when in use / always).
  • This prompt does not appear immediately and the background event that triggered the location prompt is stored for a limited time.
  • If a user allows access, your app receives the location. This will not be realtime due to the prompt not being shown immediately. Events that are too old are dropped. Plan for this.
  • If you request when in use location, you don't receive the provisional always authorization.
  • in iOS 13 you can now always use all the different location apis, like for instance region monitoring, visit tracking etc. This me