The popular open-source contract for web designers and developers by Stuff & Nonsense
- Originally published: 23/12/2008
- Revised date: 17/01/2014
- Original post
| import Foundation | |
| protocol ObjCConvertible {} | |
| extension String: ObjCConvertible {} | |
| extension Int: ObjCConvertible {} | |
| extension Double: ObjCConvertible {} | |
| extension Bool: ObjCConvertible {} | |
| func objCMethod(_ dict: [String: AnyObject]) { | |
| print(dict) |
| class BlockHolder { | |
| let block: () -> Void | |
| init(block: @escaping () -> Void) { | |
| self.block = block | |
| } | |
| } | |
| class Doer { | |
| func doIt() { | |
| print("done") |
| extension Location { | |
| func closestLocationOnPath(start: Location, end: Location) -> (location: Location, t: Double, distance: Double) { | |
| let pathVector = (latitude: end.latitude - start.latitude, longitude: end.longitude - start.longitude) | |
| var t = (self.latitude * pathVector.latitude - start.latitude * pathVector.latitude + self.longitude * pathVector.longitude - start.longitude * pathVector.longitude) / (pow(pathVector.latitude,2) + pow(pathVector.longitude,2)) | |
| t = min(max(t, 0), 1) | |
| let closestLocation = Location(latitude: start.latitude + t * pathVector.latitude, longitude: start.longitude + t * pathVector.longitude) | |
| return (location: closestLocation, t: t, distance: distance(to: closestLocation)) | |
| } | |
| func distance(to other: Location) -> Double { |
| #!/bin/sh | |
| # Based on https://gist.github.com/neonichu/9487584 | |
| # Now automatically updates every plugin for every version of Xcode on your machine | |
| PLIST_BUDDY=/usr/libexec/PlistBuddy | |
| function add_compatibility() { | |
| "$PLIST_BUDDY" -c "Add DVTPlugInCompatibilityUUIDs:10 string $2" \ | |
| "$1/Contents/Info.plist" |
| class MyObject: RLMObject { | |
| dynamic var property: Int = 0 | |
| } | |
| // Create some data | |
| let realm = RLMRealm.defaultRealm() | |
| realm.beginWriteTransaction() | |
| for i in 1...6 { | |
| realm.addObject(MyObject()) | |
| } |