Skip to content

Instantly share code, notes, and snippets.

View MarcoEidinger's full-sized avatar
🍫

Marco Eidinger MarcoEidinger

🍫
View GitHub Profile
@MarcoEidinger
MarcoEidinger / localAuthenticationInSimulatorAsync.swift
Created February 18, 2024 00:44
A decorator that ensures a biometric prompt in the simulator by explicitly calling LAContext.evaluatePolicy(_:localizedReason:). Helpful to improve test experience for protected keychain items in a simulator
func localAuthenticationInSimulator<T>(
evaluating policy: LAPolicy = .deviceOwnerAuthentication,
on context: LAContext = LAContext(),
beforeCalling function: @escaping () -> T?
) async -> T? {
#if targetEnvironment(simulator)
var localizedReason = context.localizedReason
if localizedReason.isEmpty {
localizedReason = "Test in simulator"
context.localizedReason = localizedReason
for identifier in TimeZone.knownTimeZoneIdentifiers {
let tz = TimeZone(identifier: identifier)!
print("// \(tz.identifier) (\(tz.abbreviation() ?? ""))")
}
// Africa/Abidjan (GMT)
// Africa/Accra (GMT)
// Africa/Addis_Ababa (GMT+3)
// Africa/Algiers (GMT+1)
// Africa/Asmara (GMT+3)
@MarcoEidinger
MarcoEidinger / findRequiredReasonAPIUsage.sh
Created August 21, 2023 19:55
A shell script to find if any "required reason API" are used in Swift or Objective-C files within that folder or subfolders
#!/bin/bash
# https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/describing_use_of_required_reason_api
searchTerms=(
# File timestamp APIs
"creationDate"
"modificationDate"
"fileModificationDate"
"contentModificationDateKey"
"creationDateKey"
@MarcoEidinger
MarcoEidinger / rsaEncryptionPKCS1.swift
Created April 6, 2023 19:03
Using Security.framework on iOS / macOS for cryptographic algorithm RSA/ECB/PKCS1Padding
import Foundation
import Security
// Function to generate RSA key pair
func generateRSAKeyPair() throws -> (privateKey: SecKey, publicKey: SecKey) {
let attributes: [String: Any] = [
kSecAttrKeyType as String: kSecAttrKeyTypeRSA,
kSecAttrKeySizeInBits as String: 2048
]
var error: Unmanaged<CFError>?
@MarcoEidinger
MarcoEidinger / open-iterm-from-xcode.sh
Last active November 10, 2022 02:31
Open iTerm from Xcode (optimized)
#!/bin/sh
dir="$PWD"
# remove a potential suffix in case Xcode shows a Swift Package
suffix="/.swiftpm/xcode"
dir=${dir//$suffix/}
open -a iterm "$dir"
@MarcoEidinger
MarcoEidinger / CalendarView.swift
Created August 20, 2022 21:57
Example for a view and its LibraryContentProvider implementation
import SwiftUI
/// Example of an reusable SwiftUII view available in the Xcode library
struct CalendarView: View {
var body: some View {
Text("A fake calendar view :)")
}
}
@available(iOS 14.0, *)
@MarcoEidinger
MarcoEidinger / _swift
Last active October 28, 2022 17:18
Fixed ZSH Completion Script for SPM (Swift 5.7 with small modification to include https://github.com/apple/swift-package-manager/pull/5852)
#compdef swift
local context state state_descr line
_swift_commandname=$words[1]
typeset -A opt_args
_swift() {
integer ret=1
local -a args
args+=(
'(-h --help)'{-h,--help}'[Show help information.]'
@MarcoEidinger
MarcoEidinger / README.md
Last active April 4, 2024 03:34
[Markdown] An option to highlight a "Note" and "Warning" using blockquote (Beta) #16925

A controversial beta feature in GitHub


Note highlight a "Note" using blockquote (Beta)


or


Warning

@MarcoEidinger
MarcoEidinger / GeneratedResponseTypes.swift
Created August 2, 2022 01:09
Example of using GraphQL in Swift
// This file was generated from JSON Schema using quicktype, do not modify it directly.
// To parse the JSON, add this file to your project and do:
//
// let gitHubGraphQLResponse = try? newJSONDecoder().decode(GitHubGraphQLResponse.self, from: jsonData)
import Foundation
// MARK: - GitHubGraphQLResponse
struct GitHubGraphQLResponse: Codable {
var data: DataClass?
@MarcoEidinger
MarcoEidinger / CircularProfileImage.swift
Created June 28, 2022 00:08
Working example of using PhotosPicker in a SwiftUI application (verified on Xcode 14 Beta 2 and iOS 16 simulator)
import SwiftUI
struct CircularProfileImage: View {
let imageState: ProfileModel.ImageState
var body: some View {
ProfileImage(imageState: imageState)
.frame(width: 100, height: 100)
.clipShape(Circle())
.background {