This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Cloudant.swift | |
// | |
// Created by Stefan Kruger on 19/08/2014. | |
// Copyright (c) 2014 Stefan Kruger. All rights reserved. | |
// | |
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file | |
// except in compliance with the License. You may obtain a copy of the License at | |
// http://www.apache.org/licenses/LICENSE-2.0 | |
// Unless required by applicable law or agreed to in writing, software distributed under the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import JavaScriptCore | |
public class GeoWrapper { | |
var jsContext: JSContext | |
public init?() { | |
jsContext = JSContext() | |
jsContext.exceptionHandler = { NSLog("ERROR: '%@'", $1) } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OsGridRef.toWGS84 = function(str) { | |
var grid = OsGridRef.parse(str); | |
var pOSGB36 = OsGridRef.osGridToLatLon(grid); | |
var pWGS84 = pOSGB36.convertDatum(LatLonE.datum.WGS84); | |
var latlon = pWGS84.toString(format="d"); | |
return latlon; | |
} | |
var convert = function(str) { | |
return OsGridRef.toWGS84(str) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
enum Tech { | |
case UK(level: Int, modifier: Character) | |
init?(level: Int, modifier: Character) { | |
if (4..<7 ~= level) && (find(["a", "b", "c"] as [Character], modifier) != nil) { | |
self = .UK(level: level, modifier: modifier) | |
} else { | |
return nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
enum Grade: Printable { | |
case UKTrad(adjectival: String, technical: String?) | |
var description: String { | |
switch self { | |
case let UKTrad(adjectival, technical): | |
if technical == nil { | |
return adjectival |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let flyingButtressDirect = Grade.UKTrad(adjectival: "HVS", technical: "5b") | |
// In a playground we need the .description | |
println(flyingButtressDirect.description) // HVS 5b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Adjectival: Printable { | |
case Diff, VeryDifficult, Severe, HardSevere, VerySevere, HardVerySevere, Extreme(level: Int), Error | |
var description: String { | |
switch self { | |
case Diff: | |
return "D" | |
case VeryDifficult: | |
return "VDiff" | |
case Severe: | |
return "S" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Grade: Printable { | |
case UKTrad(adjectival: Adjectival, technical: String?) | |
var description: String { | |
switch self { | |
case let UKTrad(adjectival, technical): | |
if technical == nil { | |
return adjectival.description | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let leftWall = Grade.UKTrad(adjectival: .Extreme(level: 2), technical: "5b") | |
println(leftWall.description) // E2 5b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Tech { | |
case UK(level: Int, modifier: Character) | |
init?(level: Int, modifier: Character) { | |
if (4..<7 ~= level) && (find(["a", "b", "c"] as [Character], modifier) != nil) { | |
self = .UK(level: level, modifier: modifier) | |
} else { | |
return nil | |
} | |
} |
OlderNewer