<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Robert A. Chalmers</title>
    <description>The latest articles on DEV Community by Robert A. Chalmers (@r_a_chalmers).</description>
    <link>https://dev.to/r_a_chalmers</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F163573%2F0bbcb73c-f17e-487b-95e8-924c96e1c805.jpg</url>
      <title>DEV Community: Robert A. Chalmers</title>
      <link>https://dev.to/r_a_chalmers</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/r_a_chalmers"/>
    <language>en</language>
    <item>
      <title>A Score Card for Golf, using Realm and Swift5</title>
      <dc:creator>Robert A. Chalmers</dc:creator>
      <pubDate>Sun, 05 May 2019 19:31:15 +0000</pubDate>
      <link>https://dev.to/r_a_chalmers/a-score-card-for-golf-using-realm-and-swift5-5h8j</link>
      <guid>https://dev.to/r_a_chalmers/a-score-card-for-golf-using-realm-and-swift5-5h8j</guid>
      <description>&lt;p&gt;The story begins here. My first post to Dev.to.&lt;br&gt;
Begun: May 5th, 20129. &lt;br&gt;
Last Edited/Updated: May 8th, 2019&lt;/p&gt;

&lt;p&gt;Wherein I am following the stages of development for my Swift + Realm Golf Scorecard.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Part 1.&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;I'm building a 1 to many database, keeping track of scores on a particular course.&lt;/p&gt;

&lt;p&gt;The database objects as I see them so far. This first part is in a Class I've called Game. Here I can have up to 4 players keeping their scores for a game.&lt;br&gt;
So this is the "many" - and this score and player group is for a particular Course. The 1 of the 1-to-many.&lt;/p&gt;

&lt;p&gt;Game.swift&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  class Game: Object {
  // Date game played and description or name of course
  @objc dynamic var played = Date()
  @objc dynamic var gameDescription = ""
  @objc dynamic var created = Date()
  // names of up to 4 players
  @objc dynamic var nameA = ""
  @objc dynamic var nameB = ""
  @objc dynamic var nameC = ""
  @objc dynamic var nameD = ""
// hole number and details
  @objc dynamic var holeNumber = 0.0
  @objc dynamic var holeScoreA = 0.0
  @objc dynamic var holeScoreB = 0.0
  @objc dynamic var holeScoreC = 0.0
  @objc dynamic var holeScoreD = 0.0

  @objc dynamic var holePar = 0.0
  @objc dynamic var holeDistance = 0.0
  @objc dynamic var latitude = 0.0
  @objc dynamic var longitude = 0.0

  @objc dynamic var coursename: Course!
  }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The Course object is much simpler so far. This is the 1 element of the 1-to-many arrangement.&lt;/p&gt;

&lt;p&gt;Course.swift&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Course: Object {
    @objc dynamic var coursename = ""
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;Part 2&lt;/h3&gt;

&lt;p&gt;Concurrently working on Mapbox maps to go with the project.&lt;/p&gt;

&lt;p&gt;Maps at &lt;a href="https://studio.mapbox.com"&gt;https://studio.mapbox.com&lt;/a&gt;&lt;br&gt;
and the Opening tutorial at&lt;br&gt;
&lt;a href="https://docs.mapbox.com/help/tutorials/first-steps-ios-sdk/"&gt;https://docs.mapbox.com/help/tutorials/first-steps-ios-sdk/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I started with using the Main.storyboard option to start with, but reverted to the Swift Code version due to problems with XCode errors that I didn't have the patience to solve. Code gives me more control anyway.&lt;/p&gt;

&lt;p&gt;In the code on their web page you will note that the Copy elements do not always lign up with the code you need. So copy the whole thing.&lt;/p&gt;

&lt;p&gt;The bit of their code that is depreciated in that first section you will see commented in my code below.&lt;/p&gt;

&lt;p&gt;In short:&lt;br&gt;
this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let camera = MGLMapCamera(lookingAtCenter: annotation.coordinate, fromDistance: 4500, pitch: 15, heading: 180)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;should be this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let camera = MGLMapCamera(lookingAtCenter: mapView.centerCoordinate, altitude: 4500, pitch: 15, heading: 180)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//
//  ViewController.swift
//  MapBoxTutoriaCodeVersion
//
//  Created by Robert Chalmers on 08/05/2019.
//  Copyright © 2019 R.A.Chalmers. All rights reserved.
//

import UIKit
import Mapbox

class ViewController: UIViewController, MGLMapViewDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        let url = URL(string: "mapbox://styles/rachalmers/cjvcj22si4bjh1fqugod4sfyh")
        let mapView = MGLMapView(frame: view.bounds, styleURL: url)
        mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        mapView.setCenter(CLLocationCoordinate2D(latitude: 52.088122, longitude: 1.284371), zoomLevel: 16.08, animated: false)
        view.addSubview(mapView)
        mapView.styleURL = MGLStyle.satelliteStyleURL
        // Add a point annotation
        let annotation = MGLPointAnnotation()

        annotation.coordinate = CLLocationCoordinate2D(latitude: 52.088122, longitude: 1.284371)
        annotation.title = "Seckford Golf Club"
        annotation.subtitle = "Suffolk's best golf club!"
        mapView.addAnnotation(annotation)

        // Set the map view's delegate

        mapView.delegate = self

        // Allow the map view to display the user's location
        mapView.showsUserLocation = true
    }

    func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -&amp;gt; Bool {
        // Always allow callouts to popup when annotations are tapped.
        return true
    }

    func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation) {
        //let camera = MGLMapCamera(lookingAtCenter: annotation.coordinate, fromDistance: 4500, pitch: 15, heading: 180)
        //let camera = MGLMapCamera(lookingAtCenter centerCoordinate: annotation.coordinate, fromDistance: 4500, pitch: 15, heading: 180)
        let camera = MGLMapCamera(lookingAtCenter: mapView.centerCoordinate, altitude: 4500, pitch: 15, heading: 180)
        //'init(lookingAtCenter:fromDistance:pitch:heading:)' is deprecated: Use -cameraLookingAtCenterCoordinate:acrossDistance:pitch:heading: or -cameraLookingAtCenterCoordinate:altitude:pitch:heading:.
        mapView.fly(to: camera, withDuration: 4,
                    peakAltitude: 3000, completionHandler: nil)
    }


    }

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;But otherwise, so far so good.&lt;br&gt;
The first map is here. &lt;a href="https://api.mapbox.com/styles/v1/rachalmers/cjvcj22si4bjh1fqugod4sfyh.html?fresh=true&amp;amp;title=true&amp;amp;access_token=pk.eyJ1IjoicmFjaGFsbWVycyIsImEiOiJjanZjN3QxODYxNjlwNGRwN3kzb3NhNjVyIn0.UkqUjp5Nttg2YZS94X1ORQ#15.1/52.087815/1.287832/0"&gt;MapBox Map&lt;/a&gt;&lt;/p&gt;

</description>
      <category>realm</category>
      <category>swift5</category>
      <category>ios</category>
      <category>mapbox</category>
    </item>
  </channel>
</rss>
