Skip to content

Instantly share code, notes, and snippets.

View alexkent's full-sized avatar

alex kent alexkent

  • Bontouch
  • Östersund
View GitHub Profile
@alexkent
alexkent / update_build_number.sh
Created December 7, 2016 22:47
update build number during as build phase
#!/bin/bash
# update_build_number.sh
# Usage: `update_build_number.sh [branch]`
# Run this script after the 'Copy Bundle Resources' build phase
# Ref: http://tgoode.com/2014/06/05/sensible-way-increment-bundle-version-cfbundleversion-xcode/
branch=${1:-'develop'}
buildNumber=$(expr $(git rev-list $branch --count) - $(git rev-list HEAD..$branch --count))
echo "Updating build number to $buildNumber using branch '$branch'."
import Foundation
let string = "e5cfb500"
for var index = string.startIndex; index < string.endIndex; index = index.advancedBy(2) {
let rangeOfCharacterPair = Range<String.Index>(index..<index.advancedBy(2))
let characterPair = string.substringWithRange(rangeOfCharacterPair)
print(characterPair)
}
@alexkent
alexkent / UIViewController+StoryboardConvenience.swift
Created December 21, 2015 15:15
instantiate your UIViewController subclass from a storyboard with slightly prettier casting.
import Foundation
extension UIViewController {
class func fromStoryboard(name: String, identifier: String? = .None, bundle: NSBundle? = .None) -> Self? {
return fromStoryboardHelper(self, name: name, identifier: identifier, bundle: bundle)
}
private class func fromStoryboardHelper<T: UIViewController>(type: T.Type, name: String, identifier: String?, bundle: NSBundle?) -> T? {
if let identifier = identifier {
xcrun llvm-cov report -use-color=true -instr-profile \
./Build/Intermediates/CodeCoverage/Coverage.profdata \
./Build/Intermediates/CodeCoverage/MyApp/Products/Debug-iphonesimulator/MyApp.app/MyApp
extension NSObject {
func typeNameWithOutModuleName() -> String {
var typeNameHeirarchy = NSStringFromClass(self.dynamicType).componentsSeparatedByString(".")
typeNameHeirarchy.removeFirst()
return typeNameHeirarchy.joinWithSeparator(".")
}
}
import Foundation
var strings = ["one", "two", "three", "four"]
extension Array {
func mapFilter<U>(transform: (T) -> U?) -> [U] {
var o = [U]()
for e in self {
@alexkent
alexkent / gist:7573141750237fcfc258
Created September 4, 2014 11:32
swift method argument names are weird with blocks
import Foundation
class Thing {
func doStuff(stuff:String) {
}
func doStuffWithAThing(stuff:String, athing:String) {
}
func doStuffWithTwoThings(stuff:String, thingOne:String, thingTwo:String) {
import Cocoa
class Thing:NSObject {
func a() {
println("a")
}
}
extension Thing {
// func a() {
import Foundation
class foo {
var bar:String!
func print() {
println("some stuff and \(self.bar)")
}
import Foundation
public class Thing: NSObject {
public enum State {
case yes, no, maybe
}
public var state:State
internal init() {