Skip to content

Instantly share code, notes, and snippets.

View NSExceptional's full-sized avatar

Tanner Bennett NSExceptional

View GitHub Profile
//
// Tweak.m
// FLEXing
//
// Created by Tanner Bennett on 2016-07-11
// Copyright © 2016 Tanner Bennett. All rights reserved.
//
#import "Interfaces.h"
@NSExceptional
NSExceptional / Model.swift
Last active July 23, 2016 22:32
Building a basic parser with NSScanner. In this example, to parse Objective-C interface and protocol definitions.
import Cocoa
public class Model {
public init() {}
public var className: NSString?
public var superclassName: NSString?
public var categoryname: NSString?
@NSExceptional
NSExceptional / ResponseParser.swift
Last active February 21, 2018 22:55
A simple class to automate the parsing of an NSURLSessionTask response.
//
// Copyright © 2016 Tanner Bennett. All rights reserved.
//
import Foundation
typealias ResponseParserBlock = (ResponseParser) -> Void
class ResponseParser {
@NSExceptional
NSExceptional / static_nsarray.m
Created July 29, 2016 22:52
Macro to make a static NSArray within a function or method
#define StaticNSArray(name, ...) nil; static dispatch_once_t ___onceToken; dispatch_once(&___onceToken, ^{ name = @[__VA_ARGS__]; })
- (void)foo {
...
static NSArray *animals = StaticNSArray(typeQualifiers, @"cat", @"dog", @"bunny");
...
}
@NSExceptional
NSExceptional / NSString+Markdown.h
Last active September 20, 2016 07:37
Snudown → NSAttributedString
@import Foundation;
@interface NSString (Markdown)
@property (nonatomic, readonly) NSAttributedString *attributedStringFromRawMarkdown;
@property (nonatomic, readonly) NSString *HTMLFromRawMarkdown;
@end
@NSExceptional
NSExceptional / unsign_xcode.sh
Last active December 14, 2016 05:42
Bash function to unsign the Xcode binary to allow loading of third party plugins again.
# Assumes the `unsign` binary is in your PATH.
# https://github.com/steakknife/unsign
#
# (Download zip, run `make`, move the generated binary to /usr/bin)
# Remove Xcode code signature, backup stored as Xcode.signed
xcunsign() {
_xcode=/Applications/Xcode.app/Contents/MacOS/Xcode
# Is Xcode installed?
function FindProxyForURL(url, host) {
return "SOCKS 10.63.19.184:8081";
}
@NSExceptional
NSExceptional / TypeEncodings.h
Last active November 20, 2016 07:28
Use the Objc runtime and va_args to determine and use method parameters at runtime.
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#define Method(sel, cls) class_getInstanceMethod(cls, sel)
#define originalIMP(m) method_getImplementation(m)
#define NSMethodSignatureOfMethod(m) [NSMethodSignature signatureWithObjCTypes:method_getTypeEncoding(m)]
#define swizzle(m, imp) method_setImplementation(m, imp)
typedef NS_ENUM(NSUInteger, TypeEncoding)
@NSExceptional
NSExceptional / JSONModelPlayground.swift
Created December 11, 2016 00:31
A concise example of deserializing a JSON response into a model object with as little "glue code" as possible.
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 }
var left = left
right.forEach { key, value in
@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 }