Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa Books




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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Cocoa Books (From: Jonathan <email@hidden>)
 >Re: Cocoa Books (From: Phil Faber <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.