Skip to content

Instantly share code, notes, and snippets.

@hirad
hirad / EasyArchives.m
Last active October 16, 2015 21:22
Fooling around with the ObjC Runtime
@interface ArchivesEasy: NSObject <NSCoding>
@end
@implementation ArchivesEasy
-(id)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super init]) {
[self enumeratePropertiesWithBlock:^(NSString *key, id value) {
[self setValue:[aDecoder decodeObjectForKey:key] forKey:key];
@hirad
hirad / ObjCNilGuard.h
Last active December 2, 2015 22:45
Objective-C Guard Macro For nil Objects
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define FOR_EACH_1(_what_, _separator_, X) _what_(X)
#define FOR_EACH_2(_what_, _separator_, X, ...) _what_(X) _separator_ FOR_EACH_1(_what_, _separator_, __VA_ARGS__)
#define FOR_EACH_3(_what_, _separator_, X, ...) _what_(X) _separator_ FOR_EACH_2(_what_, _separator_, __VA_ARGS__)
#define FOR_EACH_4(_what_, _separator_, X, ...) _what_(X) _separator_ FOR_EACH_3(_what_, _separator_, __VA_ARGS__)
#define FOR_EACH_SEP(_action_, _separator_, ...) GET_MACRO(__VA_ARGS__, FOR_EACH_4, FOR_EACH_3, FOR_EACH_2, FOR_EACH_1)(_action_, _separator_, __VA_ARGS__)
#define FOR_EACH(_action_, ...) FOR_EACH_SEP(_action_, ;, __VA_ARGS__)
@hirad
hirad / FixXcode.scpt
Created February 17, 2017 22:18
AppleScript to clean Xcode project, quit it, nuke derived data, re-open it and build
tell application "Xcode"
set workspaceFile to file of active workspace document
tell active workspace document
set res to (clean it)
repeat
if completed of res is true then
exit repeat
end if
delay 1.0
end repeat
@hirad
hirad / Persistence.swift
Created June 1, 2020 19:44
Compiler crasher
import Foundation
import Combine
private let docsDirURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
@propertyWrapper
struct Persisted<Value: Codable> {
let fileName: String
let defaultValue: Value