Skip to content

Instantly share code, notes, and snippets.

View demonar's full-sized avatar
😄
(¯`•._.•«<ÐêMøN>»•._.•´¯) -> Building mobile apps with Kotlin and Swift

Alejandro Moya demonar

😄
(¯`•._.•«<ÐêMøN>»•._.•´¯) -> Building mobile apps with Kotlin and Swift
View GitHub Profile
import Foundation
extension Float {
func format(f: String) -> String {
return String(format: "%\(f)f", self)
}
mutating func roundTo(decimals: Int) {
let divisor = pow(10.0, Float(decimals))
self = round(self * divisor) / divisor
}
import Foundation
extension NSDate {
func coolDate() -> String {
if self.minutesFromNow() < 1 {
return "Now"
} else if self.minutesFromNow() < 60 {
return numberWithSuffix(self.minutesFromNow(), "m", false)
} else if self.hoursFromNow() < 24 {
return numberWithSuffix(self.hoursFromNow(), "h", false)
@demonar
demonar / DictionaryUtils.swift
Last active August 31, 2015 23:58
Swift Static method used to remove nulls from dictionaries
import Foundation
class DictionaryUtils {
class func removeNullsFromDictionary(origin:[String:AnyObject]) -> [String:AnyObject] {
var destination:[String:AnyObject] = [:]
for key in origin.keys {
if origin[key] != nil && !(origin[key] is NSNull){
if origin[key] is [String:AnyObject] {
destination[key] = self.removeNullsFromDictionary(origin[key] as! [String:AnyObject])
} else if origin[key] is [AnyObject] {