• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Cocoa Books
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Cocoa Books
      • From: Ondra Cada <email@hidden>
References: 
 >Cocoa Books (From: Jonathan <email@hidden>)
 >Re: Cocoa Books (From: Phil Faber <email@hidden>)

  • Prev by Date: Re: C# to Objective-C translator?
  • Next by Date: Re: webkit -> print
  • Previous by thread: Re: Cocoa Books
  • Next by thread: Re: Cocoa Books
  • Index(es):
    • Date
    • Thread