Skip to content

Instantly share code, notes, and snippets.

View winkelsdorf's full-sized avatar
💻
Learn. Every day.

Frederik Winkelsdorf winkelsdorf

💻
Learn. Every day.
View GitHub Profile
import SwiftUI
struct AccessibleView: View {
@ScaledMetricCustom(relativeTo: .title) var someSize: CGFloat = 100
@ScaledFont(customFontName: "TimesNewRomanPS-BoldMT", size: 18, relativeTo: .body) var bodyFont
var body: some View {
VStack {
Rectangle()
.frame(width: someSize, height: someSize)
@propertyWrapper
struct Expirable<Value: ExpressibleByNilLiteral> {
let duration: TimeInterval
private var expirationDate = Date()
private var innerValue: Value = nil
private var hasExpired: Bool {
expirationDate < Date()
}
@fidothe
fidothe / actual.txt
Created October 30, 2014 17:28
escaping double quotes in XSLT
\hi\
@Ben-G
Ben-G / L10NTests.swift
Created June 16, 2017 20:35
Very simple automated test to ensure localizations exist and are well-formed on iOS.
import Foundation
import XCTest
/// Basic sanity check that ensures that we are able to retrieve localized strings for all languages
/// we support.
final class L10NTests: XCTestCase {
func testLocalizations() {
let locales = ["en", "es", "zh-Hans", "zh-Hant", "fi"]
for locale in locales {
//
// rfc3339.swift
// Alwyzon for iPhone and iPad
//
import Foundation
/// Parse RFC 3339 date string to NSDate
///
/// :param: rfc3339DateTimeString string with format "yyyy-MM-ddTHH:mm:ss.SSS"
//
// Deduplicated.swift
// CountriesSwiftUI
//
// Created by Alexey Naumov on 17.12.2019.
// Copyright © 2019 Alexey Naumov. All rights reserved.
//
import Foundation
import Combine
@steipete
steipete / View.swift
Created April 4, 2021 13:43
Accept dropping a file onto SwiftUI (both iOS and macOS)
.onDrop(of: [.fileURL], isTargeted: nil) { providers in
if let loadableProvider = providers.first(where: { $0.canLoadObject(ofClass: URL.self) }) {
_ = loadableProvider.loadObject(ofClass: URL.self) { fileURL, _ in
if let fileURL = fileURL, fileURL.pathExtension.lowercased() == "zip" {
self.logger.info("Dropped \(fileURL.path)")
DispatchQueue.main.async {
importer.open(zipArchiveURL: fileURL)
}
}
}
@0xmachos
0xmachos / Keychain.md
Last active February 19, 2024 06:50
Useful resources for working with iOS/ macOS Keychain API

Keychain API

kSecAttrAccessible Mapping

Protection Domain (pdmn) Keychain Accessibility Values
ck kSecAttrAccessibleAfterFirstUnlock
cku kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly
dk kSecAttrAccessibleAlways
akpu kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly
@HiddenJester
HiddenJester / UnitTestingSceneDelegateGist.md
Last active March 20, 2024 14:38
Mocking SceneDelegate for Unit Tests on iOS 13

Replacing the SceneDelegate When Running Unit Tests

Overview

I've been working through the exercises in the excellent iOS Unit Testing by Example book by Jon Reid, which I highly recommend. However, the book is in beta at the moment and there are some curveballs thrown by iOS 13 that aren't handled in the text yet. Specifically, when I hit the section about using a testing AppDelegate class I thought "This is very good. But what about the SceneDelegate?"

In Chapter 4 the recommendation is to remove the @UIApplicationMain decoration and make a manual top-level call to UIApplicationMain. To wit:

import UIKit
@ddunbar
ddunbar / xcbuild-debugging-tricks.md
Last active April 13, 2024 15:41
Xcode new build system debugging tricks

New Build System Tricks

Command Line

alias xcbuild=$(xcode-select -p)/../SharedFrameworks/XCBuild.framework/Versions/A/Support/xcbuild
# THIS DOESNT WORK YET: xcbuild openIDEConsole  # … then switch to Xcode ➡️
xcbuild showSpecs
xcbuild build <foo.pif> [—target <target>]