Skip to content

Instantly share code, notes, and snippets.

View andr3a88's full-sized avatar

Andrea Stevanato andr3a88

View GitHub Profile
@propertyWrapper
public struct AnyProxy<EnclosingSelf, Value> {
private let keyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>
public init(_ keyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>) {
self.keyPath = keyPath
}
@available(*, unavailable, message: "The wrapped value must be accessed from the enclosing instance property.")
public var wrappedValue: Value {
@JonnyBeeGod
JonnyBeeGod / CountdownTests.swift
Created December 25, 2019 06:41
This code allows for testing UNNotificationCenter and UNNotificationSettings
func testNotifications() {
// map all authorizationStatus with expected Result
let authorizationStatusMap: [UNAuthorizationStatus: Int] = [.authorized: 1, .denied: 0, .notDetermined: 0, .provisional: 1]
UNNotificationSettings.swizzleAuthorizationStatus()
authorizationStatusMap.forEach { (key: UNAuthorizationStatus, value: Int) in
UNNotificationSettings.fakeAuthorizationStatus = key
let mockCenter = UserNotificationCenterMock()
let mockCoder = MockNSCoder()
@danielmartin
danielmartin / BetterXcodeJumpToCounterpartSwift.org
Last active March 9, 2024 02:00
Add support for a better Xcode's Jump to Next Counterpart in Swift

If you work on a Swift project that follows the Model-View-ViewModel (MVVM) architecture or similar, you may want to jump to counterpart in Xcode from your view to your model, and then to your view model. (ie. by using Ctrl+Cmd+Up and Ctrl+Cmd+Down).

You can do this in recent versions of Xcode by setting a configuration default.

From a terminal, just type this command and press Enter:

defaults write com.apple.dt.Xcode IDEAdditionalCounterpartSuffixes -array-add "ViewModel" "View"
@atomicbird
atomicbird / logMilestone.swift
Last active August 22, 2023 03:41
Sometimes you just want to print a message that tells you a line of code was executed. Inspired by a tweet from Paige Sun: https://twitter.com/_PaigeSun/status/1161132108875796480
/// Log the current filename and function, with an optional extra message. Call this with no arguments to simply print the current file and function. Log messages will include an Emoji selected from a list in the function, based on the hash of the filename, to make it easier to see which file a message comes from.
/// - Parameter message: Optional message to include
/// - file: Don't use; Swift will fill in the file name
/// - function: Don't use, Swift will fill in the function name
/// - line: Don't use, Swift will fill in the line number
func logMilestone(_ message: String? = nil, file: String = #file, function: String = #function, line: Int = #line) -> Void {
#if DEBUG
// Feel free to change the list of Emojis, but don't make it shorter, because a longer list is better.
let logEmojis = ["😀","😎","😱","😈","👺","👽","👾","🤖","🎃","👍","👁","🧠","🎒","🧤","🐶","🐱","🐭","🐹","🦊","🐻","🐨","🐵","🦄","🦋","🌈","🔥","💥","⭐️","🍉","🥝","🌽","🍔","🍿","🎹","🎁","❤️","🧡","💛","💚","💙","💜","🔔"]
let logEmoji = logEmojis[abs(
@jpsim
jpsim / FB6395442.md
Created July 24, 2019 03:24
FB6395442: Running 'xcodebuild archive' on a SwiftPM product produces different results than an equivalent .xcodeproj

An Xcode project generates the following archive:

$ tree Yams-macosx.xcarchive
Yams-macosx.xcarchive
├── Info.plist
├── Products
│   └── Library
│       └── Frameworks
│           └── Yams.framework
import Foundation
@propertyWrapper
public struct Validate<Value> {
fileprivate let _isValid: (Value) -> Bool
public let asserts: Bool
public let useLastValid: Bool
public let message: (Value) -> String
@quangDecember
quangDecember / build-binary-universal-framework.sh
Last active June 18, 2021 09:55
Build Binary framework script for iOS, included fix for Xcode 10.2 headers, originally by DJ110
# Xcode 10.2
# please use within Xcode environment (Build Phases -> Run Script or Scheme -> Post Actions)
xcodebuild -version
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
env > env.txt
# Step 1. Build Device and Simulator versions
xcodebuild -project "${PROJECT_NAME}.xcodeproj" -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
@closerminds
closerminds / post_archive_script.sh
Last active February 14, 2020 10:46
Swift 5 universal framework with workaround for Xcode10.2 issue #48635615
exec > /tmp/${PROJECT_NAME}_archive.log 2>&1
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"
@Shehryar
Shehryar / aggregate-framework.sh
Created April 9, 2019 13:45
Fix for creating a fat framework using lipo in Xcode 10.2
#!/bin/sh
if [ -z "$XCODE_VERSION_CORRECT" ]
then
export SUDO_ASKPASS="${PROJECT_DIR}/../scripts/askpass.sh"
fi
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
struct CI {
static var mySecretKey: String = "$(SECRET_ENVIRONMENT_KEY)"
}