Skip to content

Instantly share code, notes, and snippets.

View phranck's full-sized avatar
🖥️
Working from home

Frank Gregor phranck

🖥️
Working from home
View GitHub Profile
@phranck
phranck / PlatformVisibility.swift
Last active August 30, 2024 00:05
A Swift view modifier to handle visibility of views for specific platforms
import SwiftUI
public struct Platform: OptionSet {
public var rawValue: UInt8
public static let iOS = Platform(rawValue: 1 << 0)
public static let macOS = Platform(rawValue: 1 << 1)
public static let tvOS = Platform(rawValue: 1 << 2)
public static let watchOS = Platform(rawValue: 1 << 3)
public static let all: Platform = [.iOS, .macOS, .tvOS, .watchOS]
@phranck
phranck / Q&A.md
Created June 10, 2022 19:18
Apple Q&A on Devtools and Swift Lounge

MY QUESTION: We are developing a brand new SwiftUI app. Among other things, this includes 3 Swift packages, which were integrated via "Add local...". When developing, this works great for all developers, because these packages are all in the same place in the filesystem (outside the actual project). The repositories of these 3 packages are private GitHub repos. How do we need to set up both Xcode and Xcode Cloud with these 3 private repo packages to make it work? How can Xcode Cloud access these 3 packages if they were only added locally to the project?

APPLE: In order for Xcode Cloud to have access to the three packages, the Xcode project that uses them needs to have URL references the repositories in which those packages reside. That will cause Xcode Cloud to check them out after checking out the main repository and before building.

You can still work with those packages locally by putting locally checked-out references to them in the same workspace as the main project in the local file syste

@phranck
phranck / Xcode Cloud Config.md
Last active June 11, 2022 19:37
How to configure Xcode and Xcode Cloud when using own Swift Packages from private GitHub repos?
import Carbon.HIToolbox
import SwiftUI
/// Keyboard layout independent keycodes
public enum ViewKeyCode: UInt16 {
case Return = 0x24
case Tab = 0x30
case Space = 0x31
case Delete = 0x33
case Escape = 0x35
@phranck
phranck / TassenGugelhupf.swift
Last active March 21, 2023 07:53
Backanleitung fuer einen Tassen-Gugelhupf
// TassenGugelhupf.swift
// Created by Frank Gregor on 18.03.23.
//
// This code compiles perfectly. Just paste it into a Playground and...
// "Let it go"
//
// You nay ask: "Why so complicated?"
// Well, the initial impulse came from this Mastodon thread:
// https://swiftdev.space/@phranck/110045414485613046
//
import PackageDescription
private var packageDependencies: [Package.Dependency] = []
private var plugins: [Target.PluginUsage] = []
// In Xcode's Build Settings I've set under "Preprocessor Macros": CI_XCODE_CLOUD=$(CI_XCODE_CLOUD)
#if CI_XCODE_CLOUD
#else
// Package Dependencies
packageDependencies.append(.package(url: "https://github.com/realm/SwiftLint.git", from: "0.51.0"))
@phranck
phranck / ffplay.txt
Created October 20, 2023 09:56
Output of the terminal command: ffplay --help
Simple media player
usage: ffplay [options] input_file
Main options:
-L show license
-h topic show help
-? topic show help
-help topic show help
--help topic show help
-version show version
@phranck
phranck / my_commits.sh
Last active November 17, 2023 12:19
Generates a structured list of Git commits by a dedicated user over a time period
#!/bin/bash
# ========================================
# ANSI Color escape codes:
# ========================================
# Black 0;30 Dark Gray 1;30
# Red 0;31 Light Red 1;31
# Green 0;32 Light Green 1;32
# Brown/Orange 0;33 Yellow 1;33
#if os(macOS)
import SwiftUI
public extension View {
func hostingWindow(_ callback: @escaping (NSWindow?) -> Void) -> some View {
background(HostingWindowFinder(callback: callback))
}
func windowTitle(_ title: String) -> some View {
hostingWindow { $0?.title = title }
/// The `=!=` operator assigns the value on the right-hand side to the variable on the left-hand side
/// only if the two values are not equal. This operator is designed for types conforming to the `Equatable` protocol.
///
/// - Parameters:
/// - lhs: The variable to be assigned a new value if not equal.
/// - rhs: The value to be assigned to the variable if it is not equal to the current value.
///
/// - Precondition: The type of the operands must conform to the `Equatable` protocol.
///
/// - Precedence: `AssignIfNotEqualPrecedence`