Skip to content

Instantly share code, notes, and snippets.

If you construct a Swift NSObject subclass with a designated initialiser that only has default parameters, for example;
{code:swift}
class SomeClass: NSObject {
private let foo: Int!
init(foo bar: Int = 1) {
foo = bar
}
}
@SpacyRicochet
SpacyRicochet / CwlRandom+NWA.swift
Created August 14, 2016 10:40
Uniformly distributed random numbers for @CocoawithLove's Xoroshiro implementation
//
// CwlRandom+NWA.swift
// Butterfly
//
// Created by Bruno Scheele on 10/07/16.
// Copyright © 2016 Noodlewerk Apps V.o.f. All rights reserved.
//
import Foundation
@SpacyRicochet
SpacyRicochet / Singletons.swift
Last active August 13, 2016 17:08
Some patterns for Singletons in Swift 2
// The easiest pattern. Just use a `static let`, which gets lazy loaded as a bonus.
class Singleton {
static let sharedInstance = Singleton()
func helloWorld() {
print("Hello world")
}
}
Singleton.sharedInstance.helloWorld() // prints "Hello world"
@SpacyRicochet
SpacyRicochet / RPGMoney.playground
Created March 22, 2016 22:52
A playground messing around with Swift unit types and operators
//: Playground - noun: a place where people can play
import UIKit
protocol Money: CustomStringConvertible {
var amount: Double { get }
var inGold: Double { get }
var symbol: String { get }
}
@SpacyRicochet
SpacyRicochet / README.md
Created February 2, 2016 11:30
Fetch 304 Test

Something to fetch

@SpacyRicochet
SpacyRicochet / Person.h
Last active January 3, 2016 09:29
Instead of overriding class initializers, consider overriding the new methods. There's only one default 'new' method, which makes autocompletion of your own custom ones a lot easier.
/** A person, with a name. */
@interface Person : NSObject
/** Creates a new person with the specified name. */
+ (id)newWithString:(NSString *)name;
@end
# Upload with HockeyApp
open -a HockeyApp "${ARCHIVE_PATH}"
# Auto increment CFBundleVersion
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"
@SpacyRicochet
SpacyRicochet / gist:6193870
Last active December 20, 2015 20:59
Interesting scripts for video and audio conversion
// For the directory 'en' find all m4v files and combine add the audio of other languages.
find * -name "*.m4v" -exec ffmpeg -i "{}" -i "../de/{}" -i "../fr/{}" -i "../nl/{}" -i "../sp/{}" -map 0 -map 1:a:0 -map 2:a:0 -map 3:a:0 -map 4:a:0 -metadata:s:a:0 language=eng -metadata:s:a:1 language=deu -metadata:s:a:2 language=fra -metadata:s:a:3 language=nld -metadata:s:a:4 language=spa -y "../all/{}" \;
// Make all audio of every m4v file mono and lower the sound bit rate to 48k. Change the size.
find * -name "*.mp4" -exec ffmpeg -i "{}" -map 0 -ac 1 -ab 48k -s 504x896 -y "../all_lq/{}" \;
// Use the following syntax to parse other extensions. Taken from: http://stackoverflow.com/a/8107281/571461
find -L . -type f -name "*.mp4" -exec sh -c 'ffmpeg -i ${1%.mp4}.wav' _ {} \;
@SpacyRicochet
SpacyRicochet / gist:5958118
Last active December 19, 2015 12:49
Mailing list subscription
_chimpKit = [[ChimpKit alloc] initWithDelegate:self andApiKey:@"APIKEY"];
NSDictionary *mergeVars = @{
@"FNAME" : @"Code name",
@"EMAIL" : @"codename@email.com",
@"BIRTHDAY" : @"dd-MM-yyyy",
@"GENDER" : @"male", // or 'female'
@"LANGUAGE" : NSLocalizedString(@"Key", nil), // localized string
@"MC_LANGUAGE" : NSLocalizedString(@"HFXMailchimpLanguageString", nil), // localized string
@"SUBSCRIBE" : @"yes", // or 'no'
};
@SpacyRicochet
SpacyRicochet / xcodesnippets
Created October 8, 2012 14:10
Useful XCode snippets
// DebugView: Adds a Quartz border around the view.
// shortcut: debugView
// scope: Function or Method
// Don't forget to #import <QuartzCore/QuartzCore.h>.
<#view#>.layer.borderColor = [UIColor cyanColor].CGColor;
<#view#>.layer.borderWidth = 1.f;
// Localized String: Makes it easier to start localizing from the get-go.