Example Enums:
enum SessionChannel: Int {
case NeedsAuthentication = 0
case VerifiedUser = 1
}
enum SessionEvent {
/// var num:Double = 12; | |
/// var num2:Float = num.f; | |
/// var num3:CGFloat = num.c; | |
/// var num4:Int = num.i; | |
/// var num5:Double = num2.d; | |
import UIKit; | |
extension Double{ | |
var c:CGFloat{ |
class func findCustomFonts(){ | |
for family in UIFont.familyNames() | |
{ | |
NSLog("%@", family as! String); | |
let fontNames = UIFont.fontNamesForFamilyName(family as! String); | |
fontNames.map{ | |
println("\($0)") | |
} |
extension DictionaryLiteralConvertible where Key == String, Value == AnyObject { | |
func magicFilter(){ | |
print("blah") | |
} | |
} | |
//WORKS | |
let test1 = [String : AnyObject]() | |
test1.magicFilter() |
class defering{ | |
// func g <T>(T? -> T?){ | |
// | |
// } | |
var defers:[(Void -> Void)] = [] | |
func fer( df:Void -> Void){ | |
defers.append((df)); | |
} |
func ?= <T:IntNumberConvertible, U:NumberConvertible>(var lhs: T, rhs: U) -> T{ | |
print("INTNUMBER") | |
let max :Double = T.max.convert() | |
let test :Double = rhs.convert() | |
if test > max{ | |
assert(false, "Conversion Loss") | |
} |
//Number classes use initializers, that take in other number types to convert between types | |
//Essentially this is what is going on: | |
//`Int(4.5)` ~is just this~ `Int.init(4.5)` | |
//Which is using `init(_ value:Double)` definid with in the `Int` class | |
//Using this knoledge we can optimize our conersions with pattern matching | |
import CoreGraphics //For CGFloat |
extension Int { | |
/// Construct an instance that approximates `other`. | |
public init(_ other: Float) | |
/// Construct an instance that approximates `other`. | |
public init(_ other: Double) | |
/// Construct an instance that approximates `other`. | |
public init(_ other: Float80) | |
} |
func ~= <T:Comparable>(lhs:T,rhs:(T,T)) -> Bool{ | |
if lhs < rhs.0{ | |
return false | |
} | |
if lhs > rhs.1{ | |
return false |
Example Enums:
enum SessionChannel: Int {
case NeedsAuthentication = 0
case VerifiedUser = 1
}
enum SessionEvent {
infix operator ?= { precedence 90 }
func ?= <T> (inout f: T, optional:T?){
let _ = optional.flatMap{f = $0}
}
Usage looks like:
store.name ?= json["name"]?.string