Skip to content

Instantly share code, notes, and snippets.

@PattyAppier
Created April 22, 2018 21:02
Show Gist options
  • Save PattyAppier/54a273d13161324081efb485e3ae4d63 to your computer and use it in GitHub Desktop.
Save PattyAppier/54a273d13161324081efb485e3ae4d63 to your computer and use it in GitHub Desktop.
PattysLucky7MapApp-0420-2018.md
```
// AppDelegate.swift
// this is the system funtion code page of this app, it is used to override func for the superclass & protocol.
// PattysMapApp2018
// Created by sendbest on 2018/4/21.
// Copyright © 2018年 sendbest. All rights reserved.
import UIKit
import MapKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
```
```
// Lucky7StoreControllerA.swift
// the page of store 1 while user click on pin named 1 in map.
// PattysMapApp2018
// Created by sendbest on 2018/4/22.
// Copyright © 2018年 sendbest. All rights reserved.
import UIKit
import MapKit
// 0422. to add protocol of 2nd, 3rd sequence. for input model dataSRC to hereby.
class Lucky7StoreControllerA: UIViewController, UITableViewDataSource, UITableViewDelegate {
// 0422. to add cell
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 4
}
internal func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! Lucky7TableViewCell
switch indexPath.row {
case 0:
cell.fieldLabel.text = "Store Name"
cell.valueLabel.text = "行善路門市"
case 1:
cell.fieldLabel.text = "Location"
cell.valueLabel.text = "內湖區行善路35號"
case 2:
cell.fieldLabel.text = "Duration"
cell.valueLabel.text = "07:00–23:00"
case 3:
cell.fieldLabel.text = "Tel Number"
cell.valueLabel.text = "02 8790 2990"
default:
cell.fieldLabel.text = ""
cell.valueLabel.text = ""
}
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
```
```
// Lucky7StoreControllerB.swift
// the page of store 2 while user click on pin named 2 in map.
// PattysMapApp2018
// Created by sendbest on 2018/4/22.
// Copyright © 2018年 sendbest. All rights reserved.
import UIKit
import MapKit
// 0422. to add protocol of 2nd, 3rd sequence. for input model dataSRC to hereby.
class Lucky7StoreControllerB: UIViewController, UITableViewDataSource, UITableViewDelegate {
// 0422. to add cell
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 4
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! Lucky7TableViewCell
switch indexPath.row {
case 0:
cell.fieldLabelB.text = "Store Name"
cell.valueLabelB.text = "行忠路門市"
case 1:
cell.fieldLabelB.text = "Location"
cell.valueLabelB.text = "行忠路30號"
case 2:
cell.fieldLabelB.text = "Duration"
cell.valueLabelB.text = "24 hrs"
case 3:
cell.fieldLabelB.text = "Tel Number"
cell.valueLabelB.text = "02 2790 6651"
default:
cell.fieldLabelB.text = ""
cell.valueLabelB.text = ""
}
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
```
```
// Lucky7StoreControllerC.swift
// the page of store 3 while user click on pin named 3 in map.
// PattysMapApp2018
// Created by sendbest on 2018/4/22.
// Copyright © 2018年 sendbest. All rights reserved.
import UIKit
import MapKit
// 0422. to add protocol of 2nd, 3rd sequence. for input model dataSRC to hereby.
class Lucky7StoreControllerC: UIViewController, UITableViewDataSource, UITableViewDelegate {
// 0422. to add cell
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 4
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! Lucky7TableViewCell
switch indexPath.row {
case 0:
cell.fieldLabelC.text = "Store Name"
cell.valueLabelC.text = "行愛路門市"
case 1:
cell.fieldLabelC.text = "Location"
cell.valueLabelC.text = "行愛路128號"
case 2:
cell.fieldLabelC.text = "Duration"
cell.valueLabelC.text = "24 hrs"
case 3:
cell.fieldLabelC.text = "Tel Number"
cell.valueLabelC.text = "02 2791 7850"
default:
cell.fieldLabelC.text = ""
cell.valueLabelC.text = ""
}
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
```
```
// Lucky7StoreControllerD.swift
// the page of store 4 while user click on pin named 4 in map.
// PattysMapApp2018
// Created by sendbest on 2018/4/22.
// Copyright © 2018年 sendbest. All rights reserved.
import UIKit
import MapKit
// 0422. to add protocol of 2nd, 3rd sequence. for input model dataSRC to hereby.class
class Lucky7StoreControllerD: UIViewController, UITableViewDataSource, UITableViewDelegate {
// 0422. to add cell
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 4
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! Lucky7TableViewCell
switch indexPath.row {
case 0:
cell.fieldLabelD.text = "Store Name"
cell.valueLabelD.text = "大潤發門市"
case 1:
cell.fieldLabelD.text = "Location"
cell.valueLabelD.text = "舊宗路一段128號"
case 2:
cell.fieldLabelD.text = "Duration"
cell.valueLabelD.text = "24 hrs"
case 3:
cell.fieldLabelD.text = "Tel Number"
cell.valueLabelD.text = "02 2796 7031"
default:
cell.fieldLabelD.text = ""
cell.valueLabelD.text = ""
}
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
```
```
// Lucky7TableViewCell.swift
// This is page to code Model in MVC.
// PattysMapApp2018
// Created by sendbest on 2018/4/22.
// Copyright © 2018年 sendbest. All rights reserved.
import UIKit
class Lucky7TableViewCell: UITableViewCell {
//0422. to add fieldlable & value lable in cell
@IBOutlet var fieldLabel: UILabel!
@IBOutlet var valueLabel: UILabel!
@IBOutlet var fieldLabelB: UILabel!
@IBOutlet var valueLabelB: UILabel!
@IBOutlet var fieldLabelC: UILabel!
@IBOutlet var valueLabelC: UILabel!
@IBOutlet var fieldLabelD: UILabel!
@IBOutlet var valueLabelD: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
```
```
// PattysMapViewController.swift
// It is 1st Page in UI
// PattysMapApp2018
// Created by sendbest on 2018/4/21.
// Copyright © 2018年 sendbest. All rights reserved.
import UIKit
import MapKit // 0421 to import framework.
// 0421 part2 add method of MKMapViewDelegate Protocol. called for mapView(_:viewFor:), so the PattysMapViewController needs to cast under the Protocol name.
class PattysMapViewController: UIViewController, MKMapViewDelegate {
// 0422, add button name "Find Your Luck 7!" to display action
@IBAction func showLucky7Message() {
let alertController = UIAlertController(title: "Lets Find Your Luck 7 Store!", message: "Plz Click on the Luck 7 Icon.", preferredStyle: UIAlertControllerStyle.alert)
alertController.addAction(UIAlertAction(title:"Lets Go!",style: UIAlertActionStyle.default, handler: nil))
present(alertController, animated: true, completion: nil)
}
// 0421 to declare the var of mapView and luckySeven.
@IBOutlet var pattysMapView: MKMapView!
// 0421 this outlay var named "pattysMapView" is set to connect with Pattys Map Viw.
/* var luckySeven: ViewController!*/
// 0421 to add code for add remark in Map.
// to transfer addr to coordinat, and pin it in the Map.
// to add code in ViewDidLoad Func.
override func viewDidLoad() {
// pattysMapView.delegate = self // why warning?
super.viewDidLoad()
// 0421 part2 add method of MKMapViewDelegate Protocol. called for mapView(_:viewFor:) in PattysMapViewController, so the PattysMapViewController needs to cast under the Protocol name. and need to define the mapView's Delegation.Then the result is the PattysMapViewController is one object of mapView's Delegation OBJC.
/* func pattysMapView(_mapView: MKMapView, viewFor annotation: MKAnnotation) ->
// MKAnnotationView? {
// let identification = "MyPin"
// if annotation.isKind(of: MKUserLocation.self) {
// return nil
// }
// var annotationView: MKPointAnnotation? //=
//pattysMapView.
// if annotationView == nil {
// annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
// annotationView?.canShowCallout = true
// }
// let leftIconView = UIImageView(frame: CGRect.init(x: 0, y: 0, width: 53, height: 53))
//leftIconView.image(named: luckySeven.image)
//annotationView? .leftCalloutAccessoryView = leftIconView
// return annotationView
}*/
/* let geoCoder = CLGeocoder()
// add if-sta tment
geoCoder.geocodeAddressString(luckySeven.location, completionHandler: { placemarks, error in
if error != nil {
print(error)
return
}
if let placemarks = placemarks {
// retreival of 1st map target spot
let placemark = placemarks[0]
// add anotation
let annotation = MKPointAnnotation()
annotation.title = self.luckySeven.name
annotation.subtitle = self.luckySeven.type
if let location = placemark.location {
annotation.coordinate = location.coordinate
// show the pin
self.pattysMapView.showAnnotations([annotation], animated: true)
self.pattysMapView.selectAnnotation(annotation, animated: true)
}
}
})*/
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
```
```
// TableViewController.swift
// it is 3rd page in UI
// PattysMapApp2018
// Created by sendbest on 2018/4/21.
import UIKit
import MapKit
class TableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
```
```
// ViewController.swift
// it is second Page in UI
// PattysMapApp2018
// Created by sendbest on 2018/4/21.
import UIKit
import MapKit
class ViewController: UIViewController {
//0421 to add code for update mehod for prepare(for:sender:)
/* override func prepare(for segue: UIStoryboardSegue, sender: Any?) { //sender: Any || AnyObjectSS
if segue.identifier == "showLuckySeven" {
let destinationController = segue.destination as! ViewController
destinationController.luckySeven = luckySeven
} else if segue.identifier == "showPattysMap" {
let destinationController = segue.destination as! PattysMapViewController
destinationController.luckySeven = luckySeven
}
}*/
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment