Linked Questions
34 questions linked to/from Read a file/URL line-by-line in Swift
0 votes
0 answers
472 views
How to read and slice a file chunk by chunk, then display as String? [duplicate]
I want to read and display a very large file of text, how do I slice it and read it chunk by chunk to avoid using huge amounts of memory? The idea is to read first 1mb for example, then convert to ...
845 votes
41 answers
548k views
Get the length of a String
How do you get the length of a String? For example, I have a variable defined like: var test1: String = "Scott" However, I can't seem to find a length method on the string.
305 votes
23 answers
222k views
Remove last character from string. Swift language
How can I remove last character from String variable using Swift? Can't find it in documentation. Here is full example: var expression = "45+22" expression = expression.substringToIndex(...
141 votes
18 answers
157k views
Objective-C: Reading a file line by line
What is the appropriate way of dealing with large text files in Objective-C? Let's say I need to read each line separately and want to treat each line as an NSString. What is the most efficient way of ...
76 votes
11 answers
70k views
Read a text file line by line in Swift?
I just started learning Swift. I have got my code to read from the text file, and the App displays the content of the entire text file. How can I display line by line and call upon that line multiple ...
54 votes
11 answers
49k views
How to read data from NSFileHandle line by line?
I have a text file having data as given e.g. ...
23 votes
3 answers
18k views
How does Apple's new programming language Swift handle blocks and asynchronous requests?
C.f. Apple's website page on Swift: https://developer.apple.com/swift/ Are there blocks in Swift like in objective-c? How are they created and called? How would do an asynchronous request in Swift? ...
7 votes
1 answer
11k views
Read lines from big text file in Swift until new line is empty: the Swift way
I have the following text file structure (the text file is pretty big, around 100,000 lines): A|a1|111|111|111 B|111|111|111|111 A|a2|222|222|222 B|222|222|222|222 B|222|222|222|222 A|a3|333|333|...
15 votes
1 answer
7k views
Stream audio from microphone via bluetooth to another iPhone
I am trying to take incoming microphone audio and stream it to another iPhone. Basically a phone call but via bluetooth. I have the audio coming in via AVAudioRecorder: func startRecording() { ...
8 votes
1 answer
9k views
How to Read and Write data to a text file in Swift using playground? [duplicate]
I read through these SO links for the answer 1. Read a file/URL line-by-line in Swift 2. Read and write data from text file Link 2 Provided me the solution but the problem is directory. It is by ...
3 votes
1 answer
7k views
How to read file into array of Ints
In my app documents folder I have a file which I am trying to read byte-per-byte into an array of UInt8 where each element represents a byte. How would I go about doing this? The file happens to be ...
9 votes
2 answers
1k views
Optimize String Parsing
I have a requirement to parse data files in "txf" format. The files may contain more than 1000 entries. Since the format is well defined like JSON, I wanted to make a generic parser like JSON, which ...
1 vote
1 answer
1k views
Some chars changed in NSString
I'm retrieving a string from url content, this way: NSString *urlStr = [NSString stringWithFormat:@"http://www.example.com/string_to_retrieve"]; NSURL *url = [NSURL URLWithString:urlStr]; NSString *...
2 votes
1 answer
2k views
Swift version of StreamReader only streams the entire file (not in chunks, which is desired)
I have been having issues processing large files. At first I was blaming the parser, so I wrote one, but still have the same issues. If I use this code to scan a 1,000,000 record file (250 MB), it ...
2 votes
3 answers
1k views
Pythonic way of reading text file using Swift
I know Python and I'm trying to learn Swift... I am trying to figure out how to just read a plain text file from an absolute file path In Python, #!/usr/bin/python path= '/users/mu/desktop/...