Created
April 24, 2018 22:57
-
-
Save PattyAppier/d1d088605fda4a751c7026257686fa05 to your computer and use it in GitHub Desktop.
PattysLucky7App-0425-2018.md
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
``` | |
// AppDelegate.swift | |
// PattysMapApp2018 | |
// Created by sendbest on 2018/4/21. | |
// Copyright © 2018年 sendbest. All rights reserved. | |
import UIKit | |
import CoreLocation | |
import MapKit | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
let pattysGPS = CLLocationManager() | |
// 0425. import Framework of Maps and Location in this project, then declare a 全域constant as same type as Class named CLLocationManager. | |
var window: UIWindow? | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
//0425. to override point for user after launching. | |
pattysGPS.requestWhenInUseAuthorization() | |
return true | |
} | |
func applicationWillResignActive(_ application: UIApplication) { | |
} | |
func applicationDidEnterBackground(_ application: UIApplication) { | |
} | |
func applicationWillEnterForeground(_ application: UIApplication) { | |
} | |
func applicationDidBecomeActive(_ application: UIApplication) { | |
} | |
func applicationWillTerminate(_ application: UIApplication) { | |
} | |
} | |
``` |
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
``` | |
// Lucky7StoreControllerA.swift | |
// 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 | |
} | |
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() | |
} | |
} | |
``` |
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
``` | |
// Lucky7StoreControllerB.swift | |
// 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 = "台北市內湖區行愛路128號" | |
case 2: | |
cell.fieldLabelB.text = "Duration" | |
cell.valueLabelB.text = "24 hrs" | |
case 3: | |
cell.fieldLabelB.text = "Tel Number" | |
cell.valueLabelB.text = "02 2791 7850" | |
default: | |
cell.fieldLabelB.text = "" | |
cell.valueLabelB.text = "" | |
} | |
return cell | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
} | |
} | |
``` |
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
``` | |
// 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! | |
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 | |
} | |
} | |
``` |
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
``` | |
// MapControllerA.swift | |
// PattysMapApp2018 | |
// Created by sendbest on 2018/4/25. | |
// Copyright © 2018年 sendbest. All rights reserved. | |
import UIKit | |
import MapKit | |
import CoreLocation | |
class MapControllerA: UITableViewController, MKMapViewDelegate, CLLocationManagerDelegate { | |
@IBOutlet weak var mapStoresA: MKMapView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// to add annotation | |
let pattysMapMark = MKPointAnnotation() | |
pattysMapMark.coordinate = CLLocationCoordinate2D(latitude: 25.056831, longitude: 121.576405) | |
pattysMapMark.title = "行善路7-11" | |
pattysMapMark.subtitle = "歡迎蒞臨,我們有熱騰騰的現煮咖啡!" | |
mapStoresA.addAnnotation(pattysMapMark) | |
mapStoresA.setCenter(pattysMapMark.coordinate, animated: true) | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
} | |
} | |
``` |
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
``` | |
// MapControllerB.swift | |
// PattysMapApp2018 | |
// Created by sendbest on 2018/4/25. | |
// Copyright © 2018年 sendbest. All rights reserved. | |
import UIKit | |
import MapKit | |
import CoreLocation | |
class MapControllerB: UITableViewController, MKMapViewDelegate, CLLocationManagerDelegate { | |
@IBOutlet weak var mapStoresB: MKMapView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let pattysMapMark2 = MKPointAnnotation() | |
pattysMapMark2.coordinate = CLLocationCoordinate2D(latitude: 25.063886, longitude: 121.580105) | |
pattysMapMark2.title = "行愛路7-11" // 25.063886,121.580105 | |
pattysMapMark2.subtitle = "這裡有好多集點,就當作自己的家吧!" | |
mapStoresB.addAnnotation(pattysMapMark2) | |
mapStoresB.setCenter(pattysMapMark2.coordinate, animated: true) | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
} | |
} | |
``` |
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
``` | |
// PattysMapViewController.swift | |
// PattysMapApp2018 | |
// Created by sendbest on 2018/4/21. | |
// Copyright © 2018年 sendbest. All rights reserved. | |
import UIKit | |
import MapKit // 0421 to import framework. | |
import CoreLocation // 0424 to import framework | |
class PattysMapViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate { // 0424. let this class to comply with the principle of Protocol. | |
// 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! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
} | |
} | |
``` |
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
``` | |
// TableViewController.swift | |
// 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() | |
} | |
} | |
``` |
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
``` | |
// ViewController.swift | |
// PattysMapApp2018 | |
// Created by sendbest on 2018/4/21. | |
import UIKit | |
import MapKit | |
class ViewController: UIViewController { // 0424. let this class to comply with the principle of Protocol. | |
//var lucky7store: Luck7Stores! // ! means i promise the value shall not be nil, but once the unwrapped optinal is nil, the App crashes. and the ? 's optional is nil. | |
@IBOutlet weak var mapView: MKMapView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// to add annotation | |
let pattysMapMark = MKPointAnnotation() | |
pattysMapMark.coordinate = CLLocationCoordinate2D(latitude: 25.056831, longitude: 121.576405) | |
pattysMapMark.title = "內湖區最熱門7-11" // 25.056831,121.576405 行善路 | |
pattysMapMark.subtitle = "welcome!" | |
mapView.addAnnotation(pattysMapMark) | |
// to let map dynamic | |
mapView.setCenter(pattysMapMark.coordinate, animated: true) | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
} | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment