Skip to content

Instantly share code, notes, and snippets.

View ElGrowZone's full-sized avatar
💭
Beaver busy

Volker Mohr ElGrowZone

💭
Beaver busy
View GitHub Profile
@blixt
blixt / xml.swift
Last active May 19, 2018 10:42
Using indirect enums to create a simplified XML generator in just a few lines of code
indirect enum Node {
case tag(String, [Node])
case text(String)
}
extension Node: CustomStringConvertible {
var description: String {
switch self {
case let .tag(name, children):
if children.count == 1, case let .some(.text(text)) = children.first {
@nicklockwood
nicklockwood / Deprecated.md
Last active March 28, 2022 08:16
Writing Objective-C framework code that works on multiple OS versions AND can be compiled using multiple SDK versions without warnings can be a PITA. Here's my approach:

Suppose we want to add support for a new iOS 8 API in our framework that replaces an older iOS 7 API. There are a few problems we might face:

  1. The new API will crash if we call it on iOS 7
  2. The new API won't compile if we build it using the iOS 7 SDK
  3. The old API will raise a deprecation warning if built with a deployment target of iOS 8 and up

These three problems require three different technical solutions:

  1. We can avoid calling the new API on an old OS version by using runtime detection (e.g. respondsToSelector:)
  2. We can avoid compiling new APIs on old SDKs using the __IPHONE_OS_VERSION_MAX_ALLOWED macro
// See: https://devforums.apple.com/message/1000934#1000934
import Foundation
// Logic
operator prefix ¬ {}
@prefix func ¬ (value: Bool) -> Bool {
return !value
}
#!/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -i -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
import Foundation
class JSON {
struct Path: Printable {
enum Element {
case Index(Int)
case Key(String)
@koenbok
koenbok / sign.py
Created May 14, 2014 13:26
Mac Desktop Code Sign Script
#!/usr/bin/env python
import os
import sys
import shutil
import subprocess
if len(sys.argv) < 3:
sys.exit("Usage: python sign.py <identity> <myApp.app>")
@mattdonnelly
mattdonnelly / UIImage+vImageScaling.h
Last active November 8, 2019 17:20
An Objective-C UIImage category for better resizing using vImage
//
// UIImage+vImageScaling.h
// UIImage+vImageScaling
//
// Created by Matt Donnelly on 03/07/2013.
// Copyright (c) 2013 Matt Donnelly. All rights reserved.
//
#import <UIKit/UIKit.h>
@spr
spr / ExampleDelegate.h
Last active March 22, 2017 10:57
An Example NSURLConnection delegate
//
// ExampleDelegate.h
// Example
//
// Created by Scott Robertson on 2/10/13.
// Copyright (c) 2013 Scott Robertson. All rights reserved.
//
#import <Foundation/Foundation.h>
@quietcricket
quietcricket / gist:1593632
Created January 11, 2012 07:58
Fuzzy string match objective-c (Levenshtein Distance Algorithm)
-(float)compareString:(NSString *)originalString withString:(NSString *)comparisonString
{
// Normalize strings
[originalString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[comparisonString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
originalString = [originalString lowercaseString];
comparisonString = [comparisonString lowercaseString];
// Step 1 (Steps follow description at http://www.merriampark.com/ld.htm)
@monkeydom
monkeydom / CompareMacro.h
Created August 24, 2011 10:33
Objective-C Compare Macro for your convenience
#if !defined(COMPARE)
#define COMPARE(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? NSOrderedAscending : (__a > __b ? NSOrderedDescending : NSOrderedSame); })
#endif