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
/// Cluster item | |
class ClusterItem: NSObject, GMUClusterItem { | |
let markerData: MarkerData // Raw data from server | |
let position: CLLocationCoordinate2D | |
init(markerData: MarkerData) { | |
self.markerData = markerData | |
self.position = markerData.position | |
} | |
} |
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
// My marker | |
class MyMaker: GMSMarker { | |
let markerData: MarkerData // Raw data from server | |
init(markerData: MarkerData) { | |
self.markerData = markerData | |
super.init() | |
self.title = markerData.title | |
self.position = markerData.position | |
} |
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
// Raw data from server | |
struct MarkerData { | |
var position: CLLocationCoordinate2D // Marker、Clustering Item 的座標 | |
var title: String // Maker 的 Title | |
var snippet: String // Maker 的 描述 | |
} |
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
// 將地圖視角中心點設定為台北 101 | |
let camera = GMSCameraPosition.camera(withLatitude: 25.033671, longitude: 121.564427, zoom: 15.0) | |
self.mapView.camera = camera | |
self.mapView.delegate = self |
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 ServerEnvironment5: Int { | |
case sit = 1 | |
case uat | |
case production | |
} | |
let serverEnvironment5 = ServerEnvironment5.init(rawValue: 2) // uat |
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
// 字串型態的隱式指派預設是 case 的字串 | |
enum ServerEnvironment3: String { | |
case sit | |
case uat | |
case production | |
} | |
let serverEnvironment3 = ServerEnvironment3.sit.rawValue // sit | |
// Int 型態沒指定則會從 0 開始 |
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
// 宣告字串的 Raw Value | |
enum ServerEnvironment1: String { | |
case sit = "https://sit.com" | |
case uat = "https://uat.com" | |
case production = "https://production.com" | |
} | |
let serverEnvironment1 = ServerEnvironment1.sit.rawValue // https://sit.com | |
// 宣告 Int 的 Raw Value |
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 列舉名稱: 原始值型別 { | |
case 成員 = 值 | |
} |
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 APIURL { | |
case login(deviceID: String) | |
case purchase(useID: String) | |
case orderDetail(useID: String, orderID: String) | |
var baseURL: String { | |
return "https://www.api.com" | |
} | |
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 Associated Value | |
let serverEnvironment = ServerEnvironment.sit(domain: "https://sit.com") | |
// 使用 Switch 語法找出 Associated Value 的值 | |
switch serverEnvironment { | |
case .sit(domain: let domain): | |
print("Sit domain: \(domain)") // Sit path: https://sit.com | |
case .uat(domain: let domain): | |
print("Uat domain: \(domain)") | |
case .production(domain: let domain): |