Re: Files and arrays
Re: Files and arrays
- Subject: Re: Files and arrays
- From: "John C. Randolph" <email@hidden>
- Date: Fri, 15 Nov 2002 10:46:30 -0800
On Thursday, November 14, 2002, at 01:27 PM, Mike Brinkman wrote:
Sorry if this is a basic question, but I don't know where to even look
for the answer. I'm sure I'll get the standard "RTFM", but I've
checked out NSFileWrapper class, but didn't see the info I was looking
for.
I want to create an array and initialize it with the contents of a
comma separated text file. There are 10 records in the text file, and
at the end of each record there is a return character (this file was
created in TextEdit in OS X, so I'm not sure what the return character
is).
I have a class Person and it's defined as:
@interface Person : NSObject {
NSString *personName;
NSString *personPic;
NSString *sex;
int age, height, weight;
}
// accessors
- (void)setPersonName:(NSString *)pName;
- (void)setPersonPic:(NSString *)pPic;
- (void)setPersonSex:(NSString *)pSex;
- (void)setAge:(int)pAge;
- (void)setHeight:(int)pHeight;
- (void)setWeight:(int)pWeight;
How would I create an array of Person and make each value go into the
correct value?
Look at the NSString methods -initWithContentsOfFile: and
-componentsSeparatedByString:. Also, for more elaborate parsing, look
at the NSScanner class.
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.