Skip to content

Instantly share code, notes, and snippets.

View correia's full-sized avatar

Jim Correia correia

  • Seattle, WA
View GitHub Profile

Keybase proof

I hereby claim:

  • I am correia on github.
  • I am jimcorreia (https://keybase.io/jimcorreia) on keybase.
  • I have a public key ASAR4cttpEDJ44yvVnhwDGEEwo2B3VyxpkgQv-r4U-yAXQo

To claim this, I am signing this object:

@correia
correia / MutableCloning.swift
Created November 4, 2017 21:26
Strongly typed NSCopying/NSMutableCopying for Swift
// Strongly typed NSCopying/NSMutableCopying for Swift
import Cocoa
protocol Clonable: NSCopying {
func clone() -> Self
}
extension Clonable {
func clone() -> Self {
// What does this program print?
import Foundation
for (var i = 0; i < 5; i++) {
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(1 * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue()) {
print(i)
}
}
@correia
correia / closure.m
Last active August 29, 2015 14:27
Putting a Swift closure in an Objective-C bridgeable dictionary.
// In Objective-C
typedef NSArray * (^ArrayReturningBlock)(void);
id BlockFromClosure(ArrayReturningBlock closure)
{
return [closure copy];
}
void CallBlockFromDictionary(NSDictionary *dictionary)
@correia
correia / command-line-args.swift
Last active August 29, 2015 14:02
A verbose alternative to NSProcessInfo.processInfo().arguments
//
// command-line-args.swift
//
// Created by Jim Correia on 6/4/14.
// Copyright (c) 2014-2015 Jim Correia. All rights reserved.
//
print("PROG_NAME = \(Process.arguments[0])")
print("ARGC = \(Process.argc)")
print("ARGV = \(Process.arguments)")
@correia
correia / swift-kvo-example.swift
Last active April 16, 2023 02:38
A quick example for how to use Foundation style KVO from Swift. (Official documentation from Apple is forthcoming.)
//
// Swift-KVO
//
// Created by Jim Correia on 6/5/14.
// Copyright (c) 2014-2015 Jim Correia. All rights reserved.
//
// Update: 6/17/2014
//
// KVOContext has gone away; use the same idiom you'd use from Objective-C for the context
//