Skip to content

Instantly share code, notes, and snippets.

View Azuritul's full-sized avatar

Wu Azuritul

  • Azuritul Studio
  • Tokyo
View GitHub Profile
@JamesSedlacek
JamesSedlacek / KeyboardToolbar.swift
Last active June 1, 2024 21:58
SwiftUI Keyboard Toolbar Workaround
//
// KeyboardToolbar.swift
//
// Created by James Sedlacek on 9/20/23.
//
import SwiftUI
import Combine
@Observable
@skymobilebuilds
skymobilebuilds / carthage-xc12.sh
Last active May 17, 2022 12:36
Xcode 13 and 12 Carthage Build Workaround
#!/bin/bash -e
echo "🤡 Applying carthage 12 and 13 workaround 🤡"
xcconfig=$(mktemp /tmp/static.xcconfig.XXXXXX)
# For Xcode 12 make sure EXCLUDED_ARCHS is set to arm architectures otherwise
# the build will fail on lipo due to duplicate architectures.
CURRENT_XCODE_VERSION=$(xcodebuild -version | grep "Build version" | cut -d' ' -f3)
echo 'EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_1200 = arm64 arm64e armv7 armv7s armv6 armv8' > $xcconfig
echo "EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_1200__BUILD_$CURRENT_XCODE_VERSION = arm64 arm64e armv7 armv7s armv6 armv8" >> $xcconfig
@AliSoftware
AliSoftware / Bindings.swift
Last active May 22, 2024 08:45
Re-implementation of @binding and @State (from SwiftUI) myself to better understand it
/*:
This is a concept re-implementation of the @Binding and @State property wrappers from SwiftUI
The only purpose of this code is to implement those wrappers myself
just to understand how they work internally and why they are needed,
⚠️ This is not supposed to be a reference implementation nor cover all
subtleties of the real Binding and State types.
The only purpose of this playground is to show how re-implementing
them myself has helped me understand the whole thing better
import Foundation
import Reachability
//Reachability
//declare this property where it won't go out of scope relative to your listener
fileprivate var reachability: Reachability!
protocol ReachabilityActionDelegate {
func reachabilityChanged(_ isReachable: Bool)
@npu3pak
npu3pak / fix_twitter_warnings.sh
Last active August 20, 2023 16:39
This script fixes all TwitterKit related warnings in XCode 10.1. Add new run script build phase with this code:
readonly MODULEMAP="${PODS_ROOT}/TwitterCore/iOS/TwitterCore.framework/Modules/module.private.modulemap"
readonly HEADER="${PODS_ROOT}/TwitterCore/iOS/TwitterCore.framework/Headers/TwitterCore.h"
if ! grep -q "TwitterCore_Private" "${MODULEMAP}"; then
cat >"${MODULEMAP}" <<EOL
module TwitterCore_Private {
}
EOL
fi
@IanKeen
IanKeen / LayoutGuideProvider.swift
Created October 31, 2017 11:57
Extension for constraints pointing to either the view or safeAreaLayoutGuide depending on availability
protocol LayoutGuideProvider {
var leadingAnchor: NSLayoutXAxisAnchor { get }
var trailingAnchor: NSLayoutXAxisAnchor { get }
var leftAnchor: NSLayoutXAxisAnchor { get }
var rightAnchor: NSLayoutXAxisAnchor { get }
var topAnchor: NSLayoutYAxisAnchor { get }
var bottomAnchor: NSLayoutYAxisAnchor { get }
var widthAnchor: NSLayoutDimension { get }
var heightAnchor: NSLayoutDimension { get }
var centerXAnchor: NSLayoutXAxisAnchor { get }
@krin-san
krin-san / CFNetworkErrors.h
Last active September 28, 2023 10:26
Apple NSURLError and CFNetworkError codes
typedef CF_ENUM(int, CFNetworkErrors) {
kCFHostErrorHostNotFound = 1,
kCFHostErrorUnknown = 2, // Query the kCFGetAddrInfoFailureKey to get the value returned from getaddrinfo; lookup in netdb.h
// SOCKS errors; in all cases you may query kCFSOCKSStatusCodeKey to recover the status code returned by the server
kCFSOCKSErrorUnknownClientVersion = 100,
kCFSOCKSErrorUnsupportedServerVersion = 101, // Query the kCFSOCKSVersionKey to find the version requested by the server
// SOCKS4-specific errors
kCFSOCKS4ErrorRequestFailed = 110, // request rejected or failed by the server
kCFSOCKS4ErrorIdentdFailed = 111, // request rejected because SOCKS server cannot connect to identd on the client
@chriseidhof
chriseidhof / sample.swift
Last active December 6, 2019 22:52
Observable References
import Foundation
// A lens is a getter and a setter combined
struct Lens<Whole, Part> {
let get: (Whole) -> Part
let set: (inout Whole, Part) -> ()
}
// We can create a lens from a key path
extension Lens {
@algal
algal / ScaleAspectFitImageView.swift
Last active September 24, 2023 10:19
UIImageView subclass that works with Auto Layout to express its desired aspect ratio
import UIKit
// known-good: Xcode 8.2.1
/**
UIImageView subclass which works with Auto Layout to try
to maintain the same aspect ratio as the image it displays.
This is unlike the usual behavior of UIImageView, where the
@laurilehmijoki
laurilehmijoki / keyboardHeightObservable.swift
Last active November 15, 2022 13:00
RxSwift Observable on iOS keyboard height
import RxSwift // Version 3.2.0
import RxCocoa // Version 3.2.0
func keyboardHeight() -> Observable<CGFloat> {
return Observable
.from([
NotificationCenter.default.rx.notification(NSNotification.Name.UIKeyboardWillShow)
.map { notification -> CGFloat in
(notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.height ?? 0
},