Re: Cocoa Books
Re: Cocoa Books
- Subject: Re: Cocoa Books
- From: Nir Soffer <email@hidden>
- Date: Tue, 18 Apr 2006 01:47:40 +0300
On 18/04/2006, at 00:27, Phil Faber wrote:
- Opening a text file and reading from it
If your text file is plain ASCII or UTF-16:
[NSString stringWithContentsOfFile:@"/path/to/file"]
If you use some other encoding, you must read the file with the correct
encoding. First get the file data:
NSData *data = [NSData dataWithContentsOfFile:@"/path/to/file"];
Then create a string from the data using the correct encoding. For
UTF-8 you can use:
NSString *string = [NSString stringWithUTF8String:[data bytes]];
For other encodings, e.g. ISO-8859-1:
NSString *string = [[NSString alloc] initWithData:data encoding:
NSISOLatin1StringEncoding];
[string autorelease];
- Displaying some text
Where? GUI? terminal?
- Asking the user and questions and getting the answer
How do you want to interact with the user?
- Sorting a small batch of numbers
Put the numbers in an NSArray and sort it.
NSArray *numbers = [NSArray arrayWithObjects:
[NSNumber numberWithInt:2],
[NSNumber numberWithInt:3],
[NSNumber numberWithInt:1],
nil];
[numbers sortedArrayUsingSelector:@selector(compare:)];
- Joining two strings together
[@"foo" stringByAppendingString:@"bar"]
I recommend to start with this great book:
http://www.bignerdranch.com/products/cocoa1.shtml
Best Regards,
Nir Soffer
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden