Skip to content

Instantly share code, notes, and snippets.

@chriseidhof
chriseidhof / parsing.swift
Last active April 16, 2023 02:38
JSON Parsing in Swift
// This code accompanies a blog post: http://chris.eidhof.nl/posts/json-parsing-in-swift.html
//
// As of Beta5, the >>= operator is already defined, so I changed it to >>>=
import Foundation
let parsedJSON : [String:AnyObject] = [
"stat": "ok",
"blogs": [
@bnickel
bnickel / UIView+BadBackgroundBehavior.m
Last active August 8, 2016 01:20
Sometimes, it's just worth it to accept the risk and do UIKit operations on a background thread; you just have to manage those risks. This category prints to the log any time you accidentally mess with setAnimationsEnabled: from a background thread and lets you set a breakpoint at SEViewAlertForUnsafeBackgroundCalls to inspect the call stack. Yo…
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
#ifdef DEBUG
void SEViewAlertForUnsafeBackgroundCalls() {
NSLog(@"----------------------------------------------------------------------------------");
NSLog(@" ");
NSLog(@"Background call to setAnimationsEnabled: detected. This method is not thread safe.");
NSLog(@"Set a breakpoint at SEUIViewDidSetAnimationsOffMainThread to inspect this call.");
@tomlokhorst
tomlokhorst / Optional+Unwrap.swift
Last active December 26, 2017 19:50
Unwrap multiple optionals in Swift 1.0
func unwrap<T1, T2>(optional1: T1?, optional2: T2?) -> (T1, T2)? {
switch (optional1, optional2) {
case let (.Some(value1), .Some(value2)):
return (value1, value2)
default:
return nil
}
}
func unwrap<T1, T2, T3>(optional1: T1?, optional2: T2?, optional3: T3?) -> (T1, T2, T3)? {
@wojteklu
wojteklu / clean_code.md
Last active July 25, 2024 11:12
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules