Skip to content

Instantly share code, notes, and snippets.

@fcanas
fcanas / gist:4324891
Created December 18, 2012 04:02
Property changes and control events are different. A reminder from testing in Cocoa.

Here's a lesson I learned testing UI components in Cocoa Touch on FCSettingsBooster.

Let's say you have some UISwitch element that you wire up programmatically:

[_theSwitch addTarget:self action:@selector(setDefaults) forControlEvents:UIControlEventValueChanged];

And you're going to try and make sure that some eventual effect is triggered by chaning the UISwitch. The fact that the setDefaults selector is called is irrelevant. In this case, we want to ensure that a completion block is called. You might think you can test it as follows:

@fcanas
fcanas / UI Components Rundown
Last active August 29, 2015 14:03
iOS Major UI Components Rundown and Resources
# Overview
Apple provides a good [introduction to view controllers](https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007457) that starts off very general and proceeds to highly technical. The introduction is probably worth reading for anyone interacting with iOS developers (_e.g._ designers and product managers. Next, I would look at a [catalog](https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Introduction.html#//apple_ref/doc/uid/TP40011313) of the "container" view controllers they encourage you to use.
# Table Views
The [table view](https://developer.apple.com/library/ios/documentation/userexperience/conceptual/tableview_iphone/AboutTableViewsiPhone/AboutTableViewsiPhone.html) is one of the heaviest hitters in iOS. It's been around since the beginning, is dead-simple to use and is _highly_ customizable.
See also UITableViewCells
# Collection Views
Collection views

Keybase proof

I hereby claim:

  • I am fcanas on github.
  • I am fcanas (https://keybase.io/fcanas) on keybase.
  • I have a public key whose fingerprint is D5AC E5A4 D764 1040 F907 DB29 42DB B883 EBAC E404

To claim this, I am signing this object:

@fcanas
fcanas / gist:149177d4932f329d92f8
Created September 26, 2014 21:08
In Reaction to Bret Victor's "Inventing on Principle"
# [Bret Victor](http://worrydream.com/)
* [Inventing on Principle](http://www.youtube.com/watch?v=PUv66718DII)
* [The Future of Programming](http://vimeo.com/71278954)
* [Stop Drawing Dead Fish](http://vimeo.com/64895205)
# Doug Engelbart
* [The Mother of All Demos](http://www.youtube.com/watch?v=yJDv-zdhzMY) - 1968 Ridiculousness
@fcanas
fcanas / ButtonSpringBehavior.swift
Last active January 16, 2018 01:56
Button Spring Behavior
import UIKit
var SpringKey :Int = 0
class ButtonSpringBehavior: NSObject {
var scaleFactor :CGFloat = 1.3
init(button: UIButton) {
super.init()
button.addTarget(self, action: #selector(springOut(sender:)), for: UIControlEvents.touchDown)
@fcanas
fcanas / gist:9a72f1981de4a9a0aa58
Last active August 29, 2015 14:12
Flipping Bits
func flipOn<T: RawOptionSetType>(value: T, change: T) -> T {
return T(rawValue: value.rawValue | change.rawValue )
}
func flipOff<T: RawOptionSetType>(value: T, change: T) -> T {
return T(rawValue: value.rawValue & ~change.rawValue )
}
func toggle<T: RawOptionSetType>(value: T, change: T) -> T {
return T(rawValue: value.rawValue ^ change.rawValue )
@fcanas
fcanas / gist:d541b089a03956ae5515
Last active August 29, 2015 14:16
Swift Church Encoding. Barely.
typealias ø = ((Int -> Int) -> Int -> Int)
func i<T>(v :T) -> T {
return v
}
func c<T>(n: Int) -> (T -> T) -> T -> T {
if n == 0 {
return { x in i }
}
@fcanas
fcanas / gist:39391b6a5670af668862
Last active August 29, 2015 14:20
Shell Game
; To run:
;
; $ lein repl
; $ (load-file "shell_game_test.clj")
(ns the-shell-game-test
(:require [clojure.test :refer :all]))
(defn move-the-ball [position, move]
(nth (concat [position] (reverse move)) (+ 1 (.indexOf move position)))
@fcanas
fcanas / gist:d3ff6c49099c38ce36e5
Created May 13, 2015 01:38
UIMandelbrot — Appropriate for Xcode Playgrounds
import UIKit
let white = UIColor.whiteColor().CGColor
let black = UIColor.blackColor().CGColor
let w :CGFloat = 105
let h :CGFloat = 60
let size = CGSizeMake(w, h)
UIGraphicsBeginImageContextWithOptions(size, true, 0.0)
@fcanas
fcanas / Distance.swift
Created May 21, 2015 15:11
Creating a Numeric Type : Distance
public struct Distance :NumericType {
public var value :Double
public init(_ value: Double) {
self.value = value
}
}
extension Distance :IntegerLiteralConvertible {
public init(integerLiteral: IntegerLiteralType) {
self.init(Double(integerLiteral))