Skip to content

Instantly share code, notes, and snippets.

Fabian Cañas fcanas

Block or report user

Report or block fcanas

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@fcanas
fcanas / AVAsset+Catalog.swift
Created May 29, 2019
Loading AVAssets from Asset Catalogs
View AVAsset+Catalog.swift
//
// 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 / copy.swift
Created Jan 11, 2018
Copy Properties in Swift
View copy.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 Nov 12, 2017
cyclic metadata dependency detected, aborting
View crash.swift
class C<T> {
enum E {
case c(T)
}
var e: E?
}
let o = C<Int>() // Crash : cyclic metadata dependency detected, aborting
@fcanas
fcanas / FontDescriptorBug.swift
Last active Oct 22, 2017
Ordering Matters in UIFontDescriptor, a bug
View FontDescriptorBug.swift
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 / average.swift
Created Oct 7, 2017
Abstracted average function in swift
View average.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 / about.md
Last active Dec 25, 2015
JSON Serialization driven by Swift Reflection
View about.md

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 / NSData+HexString.m
Last active Sep 2, 2015
Getting a hex string out of NSData
View NSData+HexString.m
@implementation NSData (HexString)
- (NSString *)hex_hexString {
NSMutableString *out = [NSMutableString stringWithCapacity:self.length * 2];
[self enumerateByteRangesUsingBlock:^(const void *bytes, NSRange byteRange, BOOL *stop) {
for (NSUInteger i = 0; i < byteRange.length; i++) {
[out appendFormat:@"%02x", ((unsigned char *)bytes)[i]];
}
}];
return out;
View gist:c801832dda7f9e35ac59
import Cocoa
import MapKit
import CompassOSX
import CoreGraphics
/*
// Elsewhere in the code, to initiate the trace action:
@IBAction func makeTrace(sender: AnyObject) {
let traceView = MapTraceView()
View squared_same_test.swift
func squaredSame(a: [Int], b: [Int]) -> Bool {
if a.count == 0 || b.count == 0 {
return false
}
return Set(map(a, { $0 * $0 })) == Set(b)
}
let testResult = test(squaredSame)
@fcanas
fcanas / ride.swift
Created May 27, 2015
your swift ride is here
View ride.swift
func encode(name :String) -> Int {
return reduce(map(name.unicodeScalars) { Int($0.value) - 64 }, 1, *) % 47
}
func ride(group: String, comet: String) -> String {
return encode(group) == encode(comet) ? "GO" : "STAY"
}
let testData = [
("COMETQ","HVNGAT","GO"),
You can’t perform that action at this time.