Skip to content

Instantly share code, notes, and snippets.

View DuncanMC's full-sized avatar

Duncan Champney DuncanMC

  • WareTo
View GitHub Profile
@DuncanMC
DuncanMC / FilteredArray.playground
Created April 24, 2017 02:29
Filtering an array
import UIKit
struct AStruct {
let anInt: Int
let aString: String
}
var array: [AStruct]
@DuncanMC
DuncanMC / ImageViewWithGradient.playground
Created April 14, 2015 18:25
A playground to create a UIImageView with a gradient on top of it
import UIKit
import AVFoundation
class ImageViewWithGradient: UIImageView
{
let myGradientLayer: CAGradientLayer
override init(frame: CGRect)
{
@DuncanMC
DuncanMC / JSONPlayground.swift
Created April 14, 2015 12:57
A short Swift snippet demonstrating how to convert a dictionary to JSON
import UIKit
import AVFoundation
let dictionary = ["aKey": "aValue", "anotherKey": "anotherValue"]
let theJSONData = NSJSONSerialization.dataWithJSONObject(
dictionary ,
options: NSJSONWritingOptions.PrettyPrinted,
error: nil)
let theJSONText = NSString(data: theJSONData!,
encoding: NSASCIIStringEncoding)
@DuncanMC
DuncanMC / bridging casts
Last active August 29, 2015 13:57
An explanation of iOS/Mac OS bridging casts
Using Core Foundation (CF) objects in ARC
ARC makes most aspects of memory management easier, but managing CF objects is still up to you, and converting
between NSObjects and CFObjects is actually more complicated.
If you create a CF object that follows the "Create Rule" (you own an object that is created with a method with
"create" or "copy" its name) you have to release it.
In ARC, that's still true.
@DuncanMC
DuncanMC / gist:9515158
Created March 12, 2014 20:02
Creating a bezier path
UIBezierPath *aPath = [UIBezierPath UIBezierPath];
[aPath moveToPoint: CGPointMake(0, 0);
[aPath addLineToPoint: CGPointMake(0, 200)];
[aPath addLineToPoint: CGPointMake(200, 200)];
[aPath addLineToPoint: CGPointMake(200, 0)];
[[aPath closePath];