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
// The SwiftUI Lab | |
// Website: https://swiftui-lab.com | |
// Article: https://swiftui-lab.com/alignment-guides | |
import SwiftUI | |
import Observation | |
extension EnvironmentValues { | |
@Entry var alignmentModel: Model = Model() | |
} |
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
#if swift(>=5.9) | |
import Foundation | |
public struct Tuple<T, each U> { | |
private let head: T | |
private let tail: (repeat (each U)) | |
public var values: (T, repeat each U) { |
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
### Source: https://coderwall.com/p/t_sz3q/generate-uuid-at-shell-prompt | |
# alias uuid="python -c 'import sys,uuid; sys.stdout.write(str(uuid.uuid4()))' | pbcopy && pbpaste && echo" | |
alias uuid="uuidgen | tr -d '\n' | tr '[:upper:]' '[:lower:]' | pbcopy && pbpaste && echo" |
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 OrdinalNumberFormatStyle: FormatStyle { | |
func format(_ value: Int) -> String { | |
Self.ordinalFormatter.string(from: NSNumber(value: value)) ?? String(describing: value) | |
} | |
static var ordinalFormatter: NumberFormatter = { | |
let formatter = NumberFormatter() | |
formatter.numberStyle = .ordinal | |
formatter.locale = .autoupdatingCurrent | |
return formatter |
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 | |
extension AppStorage { | |
public struct Key { | |
let name: String | |
} | |
} | |
extension AppStorage { | |
public init(wrappedValue: Value, _ key: AppStorage.Key, store: UserDefaults? = nil) where Value == Bool { |
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
# update with the path to your file, | |
# /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist | |
KEYBINDINGSET='IDETextKeyBindingSet.plist' | |
plutil -insert 'User Defined' -dictionary -- "$KEYBINDINGSET" | |
# ^⇧⏎ | |
plutil -insert 'User Defined'.'Insert New Line Above Current Line' -string 'moveUp:, moveToEndOfParagraph:, insertParagraphSeparator:' -- "$KEYBINDINGSET" | |
# ^⌥⏎ | |
plutil -insert 'User Defined'.'Insert New Line Below Currnt Line' -string 'moveToEndOfParagraph:, insertParagraphSeparator:' -- "$KEYBINDINGSET" | |
# ⌘D |
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
<key>User Defined</key> | |
<dict> | |
<key>Insert New Line Above Current Line</key> | |
<string>moveUp:, moveToEndOfParagraph:, insertParagraphSeparator:</string> | |
<key>Insert New Line Below Currnt Line</key> | |
<string>moveToEndOfParagraph:, insertParagraphSeparator:</string> | |
<key>Duplicate Current Line Down</key> | |
<string>selectParagraph:, delete:, yank:, moveToBeginningOfParagraph:, yank:, moveUp:, moveToEndOfParagraph:</string> | |
</dict> |
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 CustomDatePickerExample: View { | |
@Binding private var currentDate: Date | |
@State private var currentYear: Int | |
@State private var currentMonth: Int | |
var body: some 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
extension Collection { | |
func random(pick: Int) -> [Element] { | |
return self.indices.shuffled().prefix(pick).map { self[$0] } | |
} | |
} |
NewerOlder