Me and my acquaintances are currently in the process of making a map app using Xcode and swift. However, we are struggling on how to read a text file line by line to get coordinates. We also are struggling on how to zoom into graphic coded pictures we make (like when we code a square on to the screen, how do we zoom into it) Thanks!
Replies
Here is the logic.
The file has an URL: importFileURL
0. Declare a few var
var data = "" // will contain the whole text
var linesOfFile : Array = [] // all the lines of data
var numberOfLines = 0
1. Read the file (need to check what is the encoding: String.Encoding.utf8, or String.Encoding.isoLatin1 or String.Encoding.ascii or …
do {
data = try NSString(contentsOf: importFileURL, encoding: String.Encoding.utf8.rawValue) as String
} catch {
print("Read error"
// quit
}
2. Parse data into lines
let newlineChars = CharacterSet.newlines // newline char
linesOfFile = data.components(separatedBy: newlineChars).filter{!$0.isEmpty} // Don't keep enty lines
numberOfLines = linesOfFile.count
3. Read each line and extract info
for i in 0.. // Parse the line and do what you need
}
Is that what you are looking for ?
If so, thanks to close the thread by marking this answer as correct.
You are newto the forum, so a few advices:
- Give a title that is meaningfull. Anyone here asks for help, please. So it is totally void title.
Should be: How to read a textFile line by line
- Dont ask multiple questions.
So, for the question "how to zoom into graphic coded pictures"
Open a new thread
Give it a meaningfull title
explain precisely what the problem is
show the code you have written so far (forum is not there to do the work for you !)
Note: zooming may be use gestures, use a stepper or a scroll bar
Zooming is obtained by changing the image size in a scrollView.
But that is a question for the second thread.
Did it work ?
Note: I see forum editor does not like the ..<
here is the correct line
for i in 0 ..< numberOfLines { // Parse the line and do what you need
}
If not, please explain what is the problem.