Skip to content

Instantly share code, notes, and snippets.

@TheDarkCode
Created March 10, 2016 10:20
Show Gist options
  • Save TheDarkCode/10d7ba130788dd16ee3c to your computer and use it in GitHub Desktop.
Save TheDarkCode/10d7ba130788dd16ee3c to your computer and use it in GitHub Desktop.
Sample swift class to use with Azure Search results being returned to client.
//
// GeoJSON.swift
// azure-search-basics
//
// Created by Mark Hamilton on 3/10/16.
// Copyright © 2016 dryverless. All rights reserved.
//
import Foundation
class AZLocation: NSObject {
private var _type: String = "Point" // "Point"
private var _coordinates: [Double]! // 0.0, 0.0
private var _crs: CRS = CRS() // type: "name", properties: [name: "EPSG:4326"]
var type: String {
get {
return _type
}
}
var coordinates: [Double] {
get {
return _coordinates
}
}
var crs: CRS {
get {
if let CRS: CRS = _crs ?? CRS() {
return CRS
}
}
}
convenience init(coords: [Double], crs: CRS) {
self.init()
self._coordinates = coords
self._crs = crs
}
convenience init(coords: [Double]) {
self.init()
self._coordinates = coords
}
override init() {
super.init()
self._coordinates = [0.0,0.0]
}
}
class CRS: NSObject {
private var _type: String = "name"
private var _properties: Dictionary<String,AnyObject>!
var type: String {
get {
return _type
}
}
var properties: Dictionary<String,AnyObject> {
get {
return _properties
}
}
convenience init(name: String) {
self.init()
self._properties.updateValue(name, forKey: "name")
}
override init() {
super.init()
self._properties.updateValue("EPSG:4326", forKey: "name")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment