Skip to content

Instantly share code, notes, and snippets.

// Creates a UIColor from a Hex string.
func colorWithHexInString(hex : String) -> UIColor {
var cString:String = hex.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).uppercaseString
if (cString.hasPrefix("#")) {
cString = cString.substringFromIndex(advance(cString.startIndex, 1))
}
if (countElements(cString) != 6) {
// Creates a UIColor from a Hex string.
func colorWithHexInString(hex : String) -> UIColor {
var cString:String = hex.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).uppercaseString
if (cString.hasPrefix("#")) {
cString = cString.substringFromIndex(advance(cString.startIndex, 1))
}
if (countElements(cString) != 6) {
@barrault01
barrault01 / gist:db9f91b229ca93f29060
Created September 22, 2014 12:20
Some Implementation of LiveNibView Subclass
//
// InputView.swift
// abcdapp
//
// Created by Antoine Barrault on 21/08/2014.
// Copyright (c) 2014 Citrus Lab. All rights reserved.
//
import UIKit
struct Env {
private static let production : Bool = {
#if DEBUG
print("DEBUG")
return false
#elseif ADHOC
print("ADHOC")
return false
#else
struct Env {
private static let production : Bool = {
#if DEBUG
print("DEBUG")
let dic = ProcessInfo.processInfo.environment
if let forceProduction = dic["forceProduction"] , forceProduction == "true" {
return true
}
return false
@barrault01
barrault01 / Dangerfile
Created April 3, 2017 12:35
Default Dangerfile generated by Danger.systems
# Sometimes it's a README fix, or something like that - which isn't relevant for
# including in a project's CHANGELOG for example
declared_trivial = github.pr_title.include? "#trivial"
# Make it more obvious that a PR is a work in progress and shouldn't be merged yet
warn("PR is classed as Work in Progress") if github.pr_title.include? "[WIP]"
# Warn when there is a big PR
warn("Big PR") if git.lines_of_code > 500
@barrault01
barrault01 / Dangerfile
Created April 3, 2017 12:35
Default Dangerfile generated by Danger.systems
# Sometimes it's a README fix, or something like that - which isn't relevant for
# including in a project's CHANGELOG for example
declared_trivial = github.pr_title.include? "#trivial"
# Make it more obvious that a PR is a work in progress and shouldn't be merged yet
warn("PR is classed as Work in Progress") if github.pr_title.include? "[WIP]"
# Warn when there is a big PR
warn("Big PR") if git.lines_of_code > 500
@barrault01
barrault01 / gist:d661dff7e361957706cb6ef443423a85
Last active April 25, 2017 13:00
Protocol declaration in objective-c
@protocol MyProtocol<NSObject>
@optional
- (void)anOptionalMethod;
@end
@objc protocol MyProtocol {
@objc optional func anOptionalMethod()
}
protocol MyProtocol {
func anOptionalMethod()
func aNotOptionalMethod()
}
extension MyProtocol {
func anOptionalMethod() {
//this is a empty implementation to allow this method to be optional
}