This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol SingletonDelegate : class { | |
func reportSingletonUpdate(value:Int) | |
} | |
class Singleton { | |
private static var privateShared : Singleton? | |
weak var delegate : SingletonDelegate? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Singleton { | |
private static var privateShared : Singleton? | |
class func shared() -> Singleton { | |
guard let uwShared = privateShared else { | |
privateShared = Singleton() | |
return privateShared! | |
} | |
return uwShared |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import XCPlayground | |
enum AnimatedTextUpdate { | |
case up | |
case down | |
case left | |
case right |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HashTypeID { | |
// shared instance | |
private static var maybeShared : HashTypeID? | |
static func sharedID() -> HashTypeID { | |
guard let shared = maybeShared else { | |
maybeShared = HashTypeID() | |
return maybeShared! | |
} | |
return shared |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func subViewStack(view:UIView, levels: [Int]) { | |
var currentLevels = levels | |
currentLevels.append(0) | |
for i in 0..<view.subviews.count { | |
currentLevels[currentLevels.count - 1] = i | |
let subView = view.subviews[i] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Array { | |
mutating func appendOptional(optionalElement : Element?) { | |
guard let el = optionalElement else { | |
return | |
} | |
append(el) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol CGRectExpand { | |
var origin : CGPoint { get set } | |
var size : CGSize { get set } | |
mutating func expand(amount amount_I: CGFloat) | |
} | |
extension CGRectExpand { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
protocol GenericProtocol { | |
typealias T | |
var list : [T] { get set } | |
func setList(list : [T]) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
var myArray = [[1],[2,2],[3,3,3]] | |
func getElementCount(array array_I : [AnyObject]) -> Int { | |
var elementCount = 0 | |
guard let nestedArray = array_I as? [[AnyObject]] else { | |
return array_I.count | |
} | |
for nest in nestedArray { | |
elementCount += getElementCount(array: nest) |