Skip to content

Instantly share code, notes, and snippets.

@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 / AVAsset+Catalog.swift
Created May 29, 2019 02:09
Loading AVAssets from Asset Catalogs
//
// AVAsset+Catalog.swift
// Micro Album
//
// Created by Fabian Canas on 5/28/19.
// Copyright © 2019 Fabian Canas. All rights reserved.
//
import AVFoundation
import MobileCoreServices
@fcanas
fcanas / about.md
Last active July 13, 2022 21:33
JSON Serialization driven by Swift Reflection

A swift playground experiment in making a Swift struct to JSON serialization.

The approach currently fails for arrays, but those can be handled much like dictionaries and optionals.

@fcanas
fcanas / FontDescriptorBug.swift
Last active November 16, 2020 18:16
Ordering Matters in UIFontDescriptor, a bug
import UIKit
/*:
# Ordering Matters in UIFontDescriptor
Oct 21, 2017, iOS 11
When creating a derived font descriptor with a font family, existing traits
such as italic or bold are overwritten or ignored.
*/
@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 / copy.swift
Created January 11, 2018 18:31
Copy Properties in Swift
import Foundation
class C {
@NSCopying var copiedName: NSString?
var noCopyName: NSString?
}
let f = NSMutableString(string: "First")
let obj = C()
@fcanas
fcanas / crash.swift
Last active November 12, 2017 19:42
cyclic metadata dependency detected, aborting
class C<T> {
enum E {
case c(T)
}
var e: E?
}
let o = C<Int>() // Crash : cyclic metadata dependency detected, aborting
@fcanas
fcanas / average.swift
Created October 7, 2017 00:19
Abstracted average function in swift
extension Sequence where Element: BinaryFloatingPoint {
func average() -> Element {
return abstractAverage(sequence: self, sum: +, div: /)
}
}
extension Sequence where Element: SignedInteger {
func average() -> Element {
return abstractAverage(sequence: self, sum: +, div: /)
}
}
@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))
@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: