extension UIApplication {
var firstKeyWindow: UIWindow? {
return UIApplication.shared.connectedScenes
.compactMap { $0 as? UIWindowScene }
.filter { $0.activationState == .foregroundActive }
.first?.keyWindow
This file contains hidden or 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://stackoverflow.com/a/72093890/2468781 | |
| defaults write com.apple.dt.Xcode ApplePersistenceIgnoreState -bool YES |
This file contains hidden or 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://www.avanderlee.com/swift/property-wrappers/ | |
| @propertyWrapper | |
| struct UserDefault<Value> { | |
| let key: String | |
| let defaultValue: Value | |
| var container: UserDefaults = .standard | |
| var wrappedValue: Value { | |
| get { |
This file contains hidden or 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/local/bin/code | |
| --wait --diff "$LOCAL" "$REMOTE" | |
| -n --wait "$MERGED" |
This file contains hidden or 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 callShell(_ command: String) throws -> String { | |
| let task = Process() | |
| let pipe = Pipe() | |
| task.standardOutput = pipe | |
| task.standardError = pipe | |
| task.arguments = ["-c", command] | |
| task.executableURL = URL(fileURLWithPath: "/bin/zsh") | |
| task.standardInput = nil |
This file contains hidden or 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 tcNumber = "{TC_NUMBER}}" | |
| let lastDigitOfTCNumber = "\(tcNumber)".suffix(1) | |
| let totalOfNumbers = tcNumber.prefix(10).reduce(0) { Int($0) + (Int("\($1)") ?? 0) } | |
| let lastDigitOfTotalNumber = "\(totalOfNumbers)".suffix(1) | |
| if | |
| tcNumber.count == 11, | |
| lastDigitOfTCNumber == lastDigitOfTotalNumber { |
This file contains hidden or 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://www.avanderlee.com/concurrency/task-groups-in-swift/ | |
| let images = try await withThrowingTaskGroup(of: UIImage.self, returning: [UIImage].self) { taskGroup in | |
| let photoURLs = try await listPhotoURLs(inGallery: "Amsterdam Holiday") | |
| for photoURL in photoURLs { | |
| taskGroup.addTask { try await downloadPhoto(url: photoURL) } | |
| } | |
| var images = [UIImage]() |
This file contains hidden or 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
| Safari : com.apple.Safari | |
| Chrome: com.google.Chrome | |
| Firefox: org.mozilla.firefox | |
| Opera: com.operasoftware.Opera | |
| // Learn Bundle Id on Termina | |
| osascript -e 'id of app "Opera"' |
This file contains hidden or 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 PhotoListConstant { | |
| static let listURL = "https://jsonplaceholder.typicode.com/photos" | |
| } | |
| enum NetworkError: Error { | |
| case invalidURL | |
| } | |
| final class PhotoListViewModel: ObservableObject { | |
| @Published var photoItems = [PhotoItemModel]() |
This file contains hidden or 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 PhotoItemModel: Codable, Identifiable { | |
| let id: Int | |
| let title: String | |
| let url: String | |
| let thumbnailUrl: String | |
| } |
NewerOlder