Chapter 23 strings ERROR!


#1

on page 151 i type if the first example code to begin the chapter and appendString does not work and it wont let me compile

/// here is my code !!

[code]#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{

@autoreleasepool {
    
    NSMutableArray *str = [[ NSMutableArray alloc] init];
    for (int i = 0; i < 10; i ++) {
        [str appendString:@" Aaron is cool!\n"];
    }
    [str writeToFile:@"/tmp/cool.txt" atomically:YES
            encoding:NSUTF8StringEncoding
               error:NULL];
    NSLog(@" done writing /tmp/cool.txt");
}
return 0;

}
[/code]

i have been retypign it for an hour googling what i did wrong but nothign works


#2

Because you are declaring your NSMutableString as NSMutableArray.

Nick
http://myfirstiphoneapp.co.uk
http://easyintervalsapp.co.uk


#3

[quote=“fujilla”]Because you are declaring your NSMutableString as NSMutableArray.

Nick
http://myfirstiphoneapp.co.uk
http://easyintervalsapp.co.uk[/quote]

but i am doing exactly what the book is asking of me to do what should i change it to


#4

You should type in:

NSMutableString *str = [[ NSMutableString alloc] init];

not:

NSMutableArray *str = [[ NSMutableArray alloc] init];

Turn off the Autopilot!


#5

We must have different books then :wink: - I urge you to have another/closer look.


#6

We must have different books then :wink: - I urge you to have another/closer look.[/quote]

My book show NSMutableString - not array.

Sometimes we tend to “skip” over code we know and not read it - for example…

while reading the above line you might read it as

NSMutabl… then skip the rest of that part of the code as you’ve assumed it’s “array” as autocomplete filled it in.