Skip to content

Instantly share code, notes, and snippets.

View clmntcrl's full-sized avatar
💌

Cyril Clément clmntcrl

💌
View GitHub Profile
@clmntcrl
clmntcrl / script.swift
Last active November 19, 2015 11:45
Scripting in Swift - Commands #1. Full post: http://clmntcrl.io/blog/scripting-in-swift-commands/
enum Command: String {
case Command1, Command2
}
func main(args: [String]) {
guard let arg1 = args.first,
command = Command(rawValue: arg1.capitalizedString) else {
// Maybe it would be a good thing to print some help...
return
}
@clmntcrl
clmntcrl / example.swift
Last active October 19, 2015 12:31
Decouple UI from Model with View Models and Controls question. http://christiantietze.de/posts/2015/10/view-model-control/
class NetworkController {
// To simplify getSomeDataFromNetwork() send request synchronously
// and return a value on success, .None on failure.
func getSomeDataFromNetwork() -> AnyObject? {}
}
struct ViewModel {
var networkController: NetworkController
@clmntcrl
clmntcrl / example.swift
Created October 19, 2015 12:02
Decouple UI from Model with View Models and Controls question to @ctietze
class NetworkController {
// To simplify getSomeDataFromNetwork() send request synchronously
// and return a value on success, .None on failure.
func getSomeDataFromNetwork() -> AnyObject? {}
}
struct ViewModel {
var networkController: NetworkController
@clmntcrl
clmntcrl / DrawingView.swift
Last active October 1, 2015 09:37
UIView, UIButton subclass with custom drawing method set on init
// DrawingView by Clément Cyril - @clmntcrl - http://clmntcrl.io/
// Copyright 2015 Clément Cyril.
import UIKit
class DrawingView: UIView {
var draw: CGRect -> Void = { _ in } {
didSet { setNeedsDisplay() }
}
@clmntcrl
clmntcrl / LocalizedString.swift
Created July 16, 2015 17:01
LocalizedString
// LocalizedString by Clément Cyril - @clmntcrl - http://clmntcrl.io/
// Copyright 2015 Clément Cyril.
import Foundation
func localizedString(string: String, comment: String = "") -> String {
return String(NSLocalizedString(string, comment: comment))
}
@clmntcrl
clmntcrl / FileLineStream.swift
Created May 20, 2015 13:37
Generator for reading file line by line.
// FileLineStream by Clément Cyril - @clmntcrl - http://clmntcrl.io/
// Copyright 2015 Clément Cyril.
import Foundation
final class FileLineStream: GeneratorType {
typealias Element = String
private var fileHandle: NSFileHandle?
@clmntcrl
clmntcrl / EchoComponent.swift
Last active August 29, 2015 14:12
Building Echo customizable log format #4. Full post: http://clmntcrl.io/blog/building-echo-customizable-log-format/.
enum EchoComponent {
case Datetime(format: String)
case Flag(flags: [EchoLevel: EchoFlag])
case Filename
case Function
case Line
case Message
case Separator(String)
}
@clmntcrl
clmntcrl / EchoComponent.swift
Last active August 29, 2015 14:12
Building Echo customizable log format #3. Full post: http://clmntcrl.io/blog/building-echo-customizable-log-format/.
enum EchoComponent {
case Datetime
case Flag
case Filename
case Function
case Line
case Message
case Separator(String)
}
@clmntcrl
clmntcrl / EchoComponent.swift
Last active August 29, 2015 14:11
Building Echo customizable log format #2. Full post: http://clmntcrl.io/blog/building-echo-customizable-log-format/.
enum EchoComponent {
case DateTime
case Flag
case Filename
case Function
case Line
case Message
}
extension EchoComponent: Printable {
public var description: String {
@clmntcrl
clmntcrl / EchoFomat.swift
Last active August 29, 2015 14:11
Building Echo customizable log format #1. Full post: http://clmntcrl.io/blog/building-echo-customizable-log-format/.
struct Echo {
var format = "[flag] [[datetime]] [[filename]:[line]] [message]"
}