Skip to content

Instantly share code, notes, and snippets.

@steipete
steipete / PSPDFUIKitMainThreadGuard.m
Last active March 10, 2024 19:23
This is a guard that tracks down UIKit access on threads other than main. This snippet is taken from the commercial iOS PDF framework http://pspdfkit.com, but relicensed under MIT. Works because a lot of calls internally call setNeedsDisplay or setNeedsLayout. Won't catch everything, but it's very lightweight and usually does the job.You might n…
// Taken from the commercial iOS PDF framework http://pspdfkit.com.
// Copyright (c) 2014 Peter Steinberger, PSPDFKit GmbH. All rights reserved.
// Licensed under MIT (http://opensource.org/licenses/MIT)
//
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
// PLEASE DUPE rdar://27192338 (https://openradar.appspot.com/27192338) if you would like to see this in UIKit.
#import <objc/runtime.h>
#import <objc/message.h>
@radex
radex / optional-assignment.swift
Last active February 29, 2016 13:29
Optional assignment operator implementation. `foo ??= bar` will evaluate and assign bar to foo if and only if foo is nil. Equivalent to `||=` in Ruby and other languages.
infix operator ??= {
associativity right
precedence 90
assignment
}
func ??= <T>(inout variable: T?, expr: @autoclosure () -> T) {
if variable == nil {
variable = expr()
}
@andymatuschak
andymatuschak / gist:2b311461caf740f5726f
Created December 28, 2014 18:17
A pragmatic and intentionally non-abstract solution to JSON decoding / initialization that doesn't require learning about five new operators.
struct User {
let id: Int
let name: String
let email: String?
}
extension User: JSONDecodable {
static func create(id: Int, name: String, email: String?) -> User {
return User(id: id, name: name, email: email)
}
@kristopherjohnson
kristopherjohnson / SystemLog.swift
Last active November 6, 2020 05:59
Demo of using the Apple System Log (ASL) API from Swift
// Note: This must be used in an Xcode project that contains a bridging header
// that includes <asl.h>
import Foundation
/// Provides high-level methods to access the raw data in
/// an ASL message.
struct SystemLogEntry {
/// Key-value pairs read from ASL message
let data: [String : String]
@pietbrauer
pietbrauer / Makefile
Created April 26, 2015 10:03
Shutdown and reset all iOS Simulators
erase_sim:
./reset_sim.sh 2>/dev/null; true
@neonichu
neonichu / yolo.sh
Created May 15, 2015 16:33
Mentions of `wireless` in the Xcode 6.3.1 runtime headers
$ grep -ri wireless *
DTDeviceKitBase/DTDKRemoteDeviceConnection.h: _Bool _wireless;
DTDeviceKitBase/DTDKRemoteDeviceConnection.h:@property(readonly, getter=isWireless) _Bool wireless; // @synthesize wireless=_wireless;
DTDeviceKitBase/DTDKRemoteDeviceToken.h: DTDKRemoteDeviceConnection *_primaryWirelessConection;
DTDeviceKitBase/DTDKRemoteDeviceToken.h:+ (id)keyPathsForValuesAffectingHasWirelessConnection;
DTDeviceKitBase/DTDKRemoteDeviceToken.h:@property(retain, nonatomic) DTDKRemoteDeviceConnection *primaryWirelessConection; // @synthesize primaryWirelessConection=_primaryWirelessConection;
DTDeviceKitBase/DTDKRemoteDeviceToken.h:- (id)takeWirelessPowerAssertionWithName:(id)arg1 deatils:(id)arg2 andTimeout:(double)arg3;
DTDeviceKitBase/DTDKRemoteDeviceToken.h:- (id)wirelessInstrumentsServer;
DTDeviceKitBase/DTDKRemoteDeviceToken.h:- (void)disableWireless;
DTDeviceKitBase/DTDKRemoteDeviceToken.h:- (id)enableWireless;
@radex
radex / wwdc2015.md
Last active August 29, 2015 14:22
WWDC (iOS 9, OS X 10.11, Swift 2.0, Xcode 7) hopes&wishes

iOS 9:

  1. Stability, stability, stability. Things should just work. Especially networking/cloud related stuff: AirDrop, Handoff, syncing, etc…
  2. Notification center that's actually useful. Instead of grouping them by apps, and failing to intelligently show the notifications I'm interested in, show the chronological stream/feed of all notifications. Don't remove anything from that feed, only gray out notifications you've tapped on/seen. So, just like Facebook notifications. Much better model.
  3. Presence awareness for more intelligent notifications. Don't give me the cacophony of notifications of all 4 devices. Devices within each other's BTLE range should have awareness of each other and know that if I'm actively using my Mac, I want notifications to only show up there.
  4. Better app folders. The 3x3 grid is bullshit design, and even worse on the iPad. Make the folder zoom in and expand into a scrolling list of apps, not a paged interface. Kinda like on the Mac
  5. Allow people to choose default a
enum Result<A,B> {
case Left(A)
case Right(B)
}
extension Result {
func reduce<R>(f: A -> R, g: B -> R) -> R {
switch self {
case .Left(let a): return f(a)
case .Right(let b): return g(b)
@fastred
fastred / NS_SWIFT_UNAVAILABLE.md
Last active February 6, 2022 15:35
NS_SWIFT_UNAVAILABLE

Results of searching for NS_SWIFT_UNAVAILABLE macro in iOS 9 and OS X 10.11 headers reveal some new Swift-specific APIs.

Highlights

GameplayKit.framework/Headers/GKEntity.h
70: - (nullable GKComponent *)componentForClass:(Class)componentClass
NS_SWIFT_UNAVAILABLE("Exposed in Swift as componentForClass<ComponentType: GKComponent>(componentClass: ComponentType.Type) -> ComponentType?");

GameplayKit.framework/Headers/GKStateMachine.h
@pietbrauer
pietbrauer / 1README.md
Last active September 9, 2016 20:44
Universal CLI for automated iOS deploys and tests

Steps

  1. Download the cli.sh and move it into a scripts/ directory and execute chmod 755 scripts/cli.sh, this will make the script executable.
  2. Export your iOS Distribution private key from your Keychain into the scripts/ folder and name it ios_distribution.p12 make sure to note down the password as we will need it later. It is highly recommended to give it a very strong password.
  3. Download your Distribution provisioning profile from the Member Center
  4. Rename the provisioning profile to Release.mobilprovision
  5. At the top of the script you may need to adjust a few values:
SCHEME="" # Your scheme