-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataRead.swift
More file actions
53 lines (46 loc) · 2.63 KB
/
DataRead.swift
File metadata and controls
53 lines (46 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// DataRead.swift
// HDAugmentedRealityDemo
//
// Created by Andrey Apet on 3/6/17.
// Copyright © 2017 Danijel Huis. All rights reserved.
//
import Foundation
public class DataRead {
var allShotsObjectArray = [InfoShot]()
public init() {
readFile()
}
//MARK: Reading the txt file
public func readFile () {
if let path = Bundle.main.path(forResource: "top10_2016", ofType: "txt") {
do {
let data = try String(contentsOfFile: path, encoding: .utf8)
let shotStrings = data.components(separatedBy: .newlines)
for stringNumber in 0...(shotStrings.count-1) {
var arrayOfWords = shotStrings[stringNumber].components(separatedBy: ";")
if arrayOfWords.count == 40 {
let info = InfoShot()
info.tournament.tourDescription = arrayOfWords[1].description
info.shot.round = arrayOfWords[9].description
info.tournament.year = arrayOfWords[2].description
info.player.playerID = arrayOfWords[4].description
info.player.playerFullName = "\(arrayOfWords[7].description) \(arrayOfWords[8].description)"
info.shot.hole = arrayOfWords[12].description
info.shot.shotNumber = arrayOfWords[16].description
info.shot.distance = arrayOfWords[23].description
info.shot.distanceToHoleAfterTheShot = arrayOfWords[28].description
info.shot.xCoordinate = arrayOfWords[33].description
info.shot.yCoordinate = arrayOfWords[34].description
info.shot.zCoordinate = arrayOfWords[35].description
// print ("Tournament year: \(info.tournament.year), player ID: \(info.player.playerID), player first name: \(info.player.playerFirstName), player last name: \(info.player.playerLastName), hole: \(info.shot.hole), shot number: \(info.shot.shotNumber), distance: \(info.shot.distance), distance to hole after shot: \(info.shot.distanceToHoleAfterTheShot), X Coordinate: \(info.shot.xCoordinate), Y Coordinate: \(info.shot.yCoordinate), Z Coordinate \(info.shot.zCoordinate)")
self.allShotsObjectArray.append(info)
}
}
print ("Readed and add \(self.allShotsObjectArray.count) objects")
} catch {
print(error.localizedDescription)
}
}
}
}