NSTimer
is a great example of an over-verbose, outdated Objective-C API. To run a simple line of code after a delay, you need to write a lot of boilerplate crap.
How about this:
NSTimer.schedule(5.seconds) {
println("Hello world!")
}
import UIKit | |
// How to make singleton classes in Swift: http://stackoverflow.com/questions/24024549/dispatch-once-singleton-model-in-swift | |
// Basically using global constants is the most easy and safe way to go | |
class APIClient: NSObject { | |
let functionSessionManager:AFHTTPSessionManager | |
class var sharedInstance:APIClient { |
#!/bin/bash | |
# | |
# This script makes an empty Swift file template. | |
# | |
# Usage: | |
# | |
# sudo ./change_xcode_template | |
# | |
# or specify the Xcode app name |
import Foundation | |
struct Meter { | |
var value: Double | |
init(_ value: Double) { | |
self.value = value | |
} | |
var mm: Double { return value * 1000.0 } |
class Regex { | |
let pattern: String | |
let options: NSRegularExpressionOptions! | |
private var matcher: NSRegularExpression { | |
return NSRegularExpression(pattern: self.pattern, options: nil, error: nil) | |
} | |
required init(pattern: String, options: NSRegularExpressionOptions = nil) { | |
self.pattern = pattern |
NSTimer
is a great example of an over-verbose, outdated Objective-C API. To run a simple line of code after a delay, you need to write a lot of boilerplate crap.
How about this:
NSTimer.schedule(5.seconds) {
println("Hello world!")
}
func ==<U: Equatable, T: protocol<RawRepresentable, Equatable> where T.RawValue == U>(lhs: U, rhs: T) -> Bool { | |
return lhs == rhs.rawValue | |
} | |
func !=<U: Equatable, T: protocol<RawRepresentable, Equatable> where T.RawValue == U>(lhs: U, rhs: T) -> Bool { | |
return lhs != rhs.rawValue | |
} |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.setUpLocationmanager() | |
let beaconSequence = locationManager.rx_didRangeBeaconsInRegion.map{$0.beacons} | |
let sortedBeaconSequence = beaconSequence.map{beacons in self.sortBeaconsByRSSI(beacons)} | |
let nearestBeaconSequence = sortedBeaconSequence.map({$0[0]}) | |
.filter{$0.proximity == CLProximity.Immediate} | |
.distinctUntilChanged{$0.minor == $1.minor} |
// (c) 2014 Nate Cook, licensed under the MIT license | |
// | |
// Fisher-Yates shuffle as top-level functions and array extension methods | |
/// Shuffle the elements of `list`. | |
func shuffle<C: MutableCollectionType where C.Index == Int>(inout list: C) { | |
let c = count(list) | |
for i in 0..<(c - 1) { | |
let j = Int(arc4random_uniform(UInt32(c - i))) + i | |
swap(&list[i], &list[j]) |
#!/bin/sh | |
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal | |
# make sure the output directory exists | |
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}" | |
# Step 1. Build Device and Simulator versions | |
xcodebuild -target "AlamoWater" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build | |
xcodebuild -target "AlamoWater" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build |
extension UITableView { | |
/** | |
Returns an index path identifying the row and section | |
of the cell containing the provided view | |
:param: cellSubview A subview of any given UITableViewCell in the table. Typically this is either a `UIButton` or `UITextField` | |
*/ | |
func indexPathForCellWithSubview(cellSubview: UIView) -> NSIndexPath? { | |
let cellFrame = convertRect(cellSubview.bounds, fromView: cellSubview) | |
let cellCenter = CGPoint(x: CGRectGetMidX(cellFrame), y: CGRectGetMidY(cellFrame)) |