Tech-Today
XCode How to read raw data from pipe-delimited text file
Open Xcode and create a new Single View Application. For product name, use ReadPipeDelimitedTextfield and then fill out the Organization Name and Company Identifier with your customary values. Select iPhone for Devices.
I have prepared a text file to be used in this project, it can be download in this link. Download the text file and add it inside the project.
Once the file has been added, go inside the "ViewController.m" and add the following lines of code inside the viewDidLoad:
NSError *error;
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"US States" ofType:@"txt"];
NSString *USStates = [NSString stringWithContentsOfFile:filePath
encoding:NSUTF8StringEncoding error:&error];
NSString *statesStripped = [USStates stringByReplacingOccurrencesOfString:@"\r" withString:@""];
NSArray *rows = [statesStripped componentsSeparatedByString:@"\n"];
NSArray *components;
for(int i = 0; i < [rows count]; i++){
if(i == 0 || [[rows objectAtIndex:i] isEqualToString:@""]){
continue;
}
components = [[rows objectAtIndex:i] componentsSeparatedByString:@"|"];
NSLog(@"State: %@ Abbr: %@", [components objectAtIndex:0], [components objectAtIndex:1]);
}
Notice how the value of "pathForResource" is equivalent to the name of the text file.
Build and Run the project, inside the console you should see the contents of the text files which are now separated.
You can download the source code of the ReadPipeDelimitedTextfield at my repository on bitbucket.
-
Location Demo In Ios 8 With Swift
What we will be doing is a simple app the tells your location base on the longitude and latitude. For making things simpler, I already set-up the UI in this link. Once you have downloaded the files go to storyboard and change the size class...
-
Xcode: Create A Simple Alertview
Open Xcode and create a new Single View Application. For product name, use SimpleAlertView and then fill out the Organization Name and Company Identifier with your customary values. Select iPhone for Devices. Drag a button inside the view controller...
-
How To Differentiate Between 3.5 And 4 Inch Iphone
Open Xcode and create a new Single View Application. For product name, use DifferentiateIphoneSize and then fill out the Organization Name and Company Identifier with your customary values. Select iPhone for Devices. For demonstration purposes, add a...
-
Display Time Picker On Textfield Click In Xcode
Open Xcode and create a new Single View Application. For product name, use TextFieldTimePicker and then fill out the Organization Name and Company Identifier with your customary values. Select iPhone for Devices. For setting up the user interface, first,...
-
Iphone Command Line Tool Development, Working With Framework Classes
iPhone command line tool development, working with framework classes I was studying iPhone when I found this video tutorial and online exercises from Stanford University. I think they offered this course last 2009. So I'm gonna follow their videos,...
Tech-Today