This is now available in a dedicated package: ActivityView
Alternatively my SwiftUI Backports now includes a more complete implementation of ShareLink
that's also more performant.
// Copyright 2021 Kyle Hughes | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | |
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the | |
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to | |
// permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
// | |
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the | |
// Software. | |
// |
extension View { | |
func relative(width: CGFloat? = nil, height: CGFloat? = nil, alignment: Alignment = .center) -> some View { | |
Color.clear | |
.frame(maxWidth: width.map { _ in .infinity }, maxHeight: height.map { _ in .infinity }) | |
.overlay(GeometryReader { proxy in | |
ZStack { | |
self.frame( | |
width: width.map { proxy.size.width * $0 }, | |
height: height.map { proxy.size.height * $0 } | |
) |
import SwiftUI | |
struct ContentView: View { | |
static var toggle = false | |
static let settings: [Setting] = [ | |
.push( | |
label: "Embedded content", | |
[ | |
.text(label: "Deeper!", "Here is some embedded informational text") | |
] |
import Foundation | |
@propertyWrapper | |
struct SimpleUserDefault<T> { | |
let userDefaults: UserDefaults | |
let key: String | |
let defaultValue: T | |
init( | |
userDefaults: UserDefaults = UserDefaults.standard, |
alias statusbarfix='xcrun simctl status_bar booted override --time 9:41 --cellularMode active --cellularBars 4 --batteryState charging --operatorName ""' |
func testCombineLatest() { | |
for _ in 1...100 { | |
let e = expectation(description: "Each subject should emit true") | |
let s1 = CurrentValueSubject<Bool, Never>(false) | |
let s2 = CurrentValueSubject<Bool, Never>(false) | |
let cancellable = Publishers.CombineLatest(s1, s2) | |
.sink { | |
if $0, $1 { | |
e.fulfill() | |
} |
/// The Jaro-Winkler edit distance between two strings (0 - 1) | |
func editDistance(_ lhs: String, _ rhs: String) -> Double { | |
return 1 - jaroWinklerSimilarity(Array(lhs), Array(rhs)) | |
} | |
/// Jaro-Winkler similarity between two strings (0 - 1) | |
/// https://www.geeksforgeeks.org/jaro-and-jaro-winkler-similarity/ | |
private func jaroWinklerSimilarity(_ s1: [Character], _ s2: [Character]) -> Double { | |
var jaro = jaroSimilarity(s1, s2) |
This is now available in a dedicated package: ActivityView
Alternatively my SwiftUI Backports now includes a more complete implementation of ShareLink
that's also more performant.
import SwiftUI | |
enum PreviewProviderMode: CaseIterable { | |
/// Use for a light appearance preview. | |
case lightMode | |
/// Use for a dark appearance preview. | |
case darkMode | |
import SwiftUI | |
protocol ViewModelContainable: View { | |
associatedtype ViewModel : ObservableObject | |
init(model: ViewModel) | |
} | |
// This struct is a direct MVVM alternative to @StateObject in iOS 14 and Mac OS Big Sur. |