Skip to content

Instantly share code, notes, and snippets.

View NSExceptional's full-sized avatar

Tanner Bennett NSExceptional

View GitHub Profile
//
// SwiftMetadata.h
// Swift Test
//
// Created by Tanner on 10/28/17.
// Copyright © 2017 Tanner Bennett. All rights reserved.
//
#import <Foundation/Foundation.h>
@NSExceptional
NSExceptional / ObjcSimulator.swift
Created October 19, 2017 20:42
A small Objective-C-like simulation in Swift.
//
// main.swift
//
// Created by Tanner Bennett on 10/19/17.
// Copyright © 2017 Tanner Bennett. All rights reserved.
//
import Foundation
// For shorthand casting
@NSExceptional
NSExceptional / CommentsViewController+LongPress.m
Last active August 16, 2017 05:03
A tweak to enable long-press to copy the text/source/link of a comment in Reddit.app
//
// CommentsViewController+LongPress.m
// RedditEasyCopy
//
// Created by Tanner Bennett on 2017-08-11
//
// This is the "non-tweak" version of the relevant code.
// The .xm file is a tweak, you can ignore it. This file
// has the code that should be put into the app itself.
//
@NSExceptional
NSExceptional / TrueHidePhotos.xm
Last active July 27, 2017 04:21
An iOS tweak to hide hidden photos everywhere except in the Hiddel album.
//
// Tweak.xm
// TrueHidePhotos
//
// Created by Tanner Bennett on 2017-07-02
// Copyright © 2017 Tanner Bennett. All rights reserved.
//
#import <Photos/Photos.h>
export TARGET = iphone:10.3:9.0
export ARCHS = arm64
include $(THEOS)/makefiles/common.mk
# Relevant folders
PROJECT_SRC = TBTweakViewController/TBTweakViewController/Classes
PODS_ROOT = TBTweakViewController/Pods
MK_DIR = /Users/tanner/Repos/MirrorKit
# Swizzle sources and all dependency sources
@NSExceptional
NSExceptional / XcodeBuildSettingsReference.md
Last active November 14, 2024 02:25
The Xcode Build Settings Reference in a searchable document, as of Xcode 8.3.2

Build settings reference

Active Build Action (ACTION)

A string identifying the build system action being performed.

Additional SDKs (ADDITIONAL_SDKS)

The locations of any sparse SDKs that should be layered on top of the one specified by Base SDK (SDKROOT). If more than one SDK is listed, the first one has highest precedence. Every SDK specified in this setting should be a "sparse" SDK, for example, not an SDK for an entire macOS release.

Alternate Install Group (ALTERNATE_GROUP)

static NSMutableURLRequest * SKMakeRequest(NSDictionary *message) {
SKIPCRequest *query = message[kQueryKey];
return [SKIPCQueryBuilder endpoint:query];
}
static void SKIPCSpringboardInit() {
// Allow passing messages to Snapchat from other apps
[OBJCIPC registerIncomingMessageFromAppHandlerForMessageName:kQueryName handler:^NSDictionary *(NSDictionary *query) {
// Delegate query to Snapchat, propagate result to caller
NSDictionary *object = [OBJCIPC sendMessageToAppWithIdentifier:kSnapchatBundleID messageName:kQueryName dictionary:query];
@NSExceptional
NSExceptional / Objc.m
Last active March 2, 2017 02:06
Code which demonstrates strangely aligned stack arguments in ARM64.
typedef struct _Bar {
long x;
long y;
long z;
} Bar;
@interface Foo : NSObject
+ (void)method:(Bar)a :(long)b :(Bar)c :(long)d :(long)e :(Bar)f :(long)g :(long)h;
@end
@implementation Foo
@NSExceptional
NSExceptional / Ideal Swift access control.md
Last active December 6, 2018 12:23
My proposal for better access control in Swift.

Problems with Swift's access control

  • Classes being "closed" by default is unusual in most OOP languages and allows for a careless developer to unknowingly write a library that restricts how it can be used by not making classes open as needed.
  • Swift's distinction between file-private and declaration-private scopes is confusing (fileprivate and private as of Swift 3) and completely unnecessary most of the time, since when one includes two top-level declarations in the same file, it's usually because the declarations are supposed to be visible to each other.

Proposed solution

  • open: all declarations are implicitly open; no open keyword.
  • final: inherits implicit visibility when none is specified.
@NSExceptional
NSExceptional / JSONModel.swift
Last active February 21, 2018 22:55
A concise example of deserializing a JSON response into a model object with as little "glue code" as possible, and some runtime type checking to avoid BAD_INSTRUCTION.
// Tanner Bennett 2016
import Foundation
typealias JSON = [String: Any]
/// For joining dictionaries; contents of `right` take preceedence over `left`
func + <K,V> (left: Dictionary<K,V>, right: Dictionary<K,V>?) -> Dictionary<K,V> {
guard let right = right else { return left }