- https://github.com/LucasMucGH/BottomSheet (works; examples work and provide a reasonable multi-height bottom drawer for swiftui, although in detail it's different from the Apple Maps one)
- https://github.com/faberNovel/DynamicOverlay (works; provides a SwiftUI example that copies the gestures of the Apple Maps app more closely, actual implementation is UIKit)
- https://swiftwithmajid.com/2019/12/11/building-bottom-sheet-in-swiftui/ (only the first step of building a drawer)
- https://github.com/weitieda/bottom-sheet (Only single height)
- https://github.com/maustinstar/swiftui-drawer (Examples don't work out of the box)
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 SizePreferenceKey: PreferenceKey { | |
static let defaultValue: CGSize = .zero | |
static func reduce(value: inout CGSize, nextValue: () -> CGSize) { | |
value = nextValue() | |
} | |
} |
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 CoreGraphics | |
import CoreImage | |
func imageMetadataString(image: CGImage) -> String { | |
return "\(image.width)x\(image.height) bitsPerComponent:\(image.bitsPerComponent) bytesPerRow:\(image.bytesPerRow) bitsPerPixel:\(image.bitsPerPixel)" | |
} | |
/** | |
@brief Returns the maximum difference of pixel values in the image. | |
@discussion Assumes doImagesHaveSameMeta has already returned true on |
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
#!/usr/bin/env ruby | |
require 'fileutils' | |
require 'xcodeproj' | |
unless ARGV.count == 2 | |
puts "Usage: xcode_set_development_region.rb [project] [region]" | |
exit(1) | |
end |
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 | |
/// Detect a Shake gesture in SwiftUI | |
/// Based on https://stackoverflow.com/a/60085784/128083 | |
struct ShakableViewRepresentable: UIViewControllerRepresentable { | |
let onShake: () -> () | |
class ShakeableViewController: UIViewController { | |
var onShake: (() -> ())? |
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 | |
import os | |
/** | |
DocumentStore stores a Codable document in the documents directory of the app. | |
- Loading and saving happens on the thread you call it on, typically the main thread. | |
- This should be only used for small documents (recommendation: smaller than 1KB). For larger documents, or if you want features like schema migration, Core Data (or some other database framework for apps like Realm) will be a better fit. | |
- This is a starting point and not to be used for critical app data: If the document cannot be loaded (f.e. because of an incompatible change of the Document type), the Document will silently be nil and be overwritten on the next save. If the document cannot be saved, it will crash. | |
*/ |
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 CoreLocation | |
import os | |
/// CurrentLocation provides the current GPS location via CLLocationManager as ObservableObject. | |
/// | |
/// - Meant to be used for 'when the app is in use', NSLocationWhenInUseUsageDescription needs to be | |
/// set in Info.plist. | |
/// | |
/// - This can be used by multiple observers but there should be a single manager object for the "isActive" property. | |
/// If multiple components want to manage isActive, maybe consider creating multiple instances (often |
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 MultipeerConnectivity | |
import os | |
import SwiftUI | |
class ColorModel: NSObject, ObservableObject { | |
private let serviceType = "example-color" | |
private let session: MCSession | |
private let myPeerId = MCPeerID(displayName: UIDevice.current.name) | |
private let serviceAdvertiser: MCNearbyServiceAdvertiser |
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
func countriesExampleData() -> [Country] { | |
[ | |
Country( | |
id: "at", | |
name: "Austria", | |
capital: "Vienna", | |
population: 8_935_112, | |
drivingSide: .right | |
), | |
Country( |
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
actor SyncActor { | |
var syncRequests = 0 | |
private func sync() async { | |
// Make sure only one sync is in progress at the same time | |
// (because of actor re-entrancy another sync could be started while we await for the persistence/network operations) | |
self.syncRequests += 1 | |
if self.syncRequests > 1 { | |
// Sync already in progress |
NewerOlder