Challenge Issue


#1

For this challenge I decided just to do it quick and dirty without much purpose. All I’m doing is creating an instance of each of the 8 types, throwing them in an array, and writing that array to a plist file. The error I’m getting is “Thread 1: EXC_BAD_ACCESS(code=1, address=0x3f0)”. I know someone else posted about this same issue but their fix was a typo thing and I haven’t found any in mine.

Code:

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

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

@autoreleasepool {
    
    // creating all of the data types
    NSArray *array = [[NSArray alloc] initWithObjects:@"Hello, World!", nil];
    NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"fluffy", @"petname", nil];
    NSString *string = @"lolcats";
    NSData *data = [[NSData alloc] initWithContentsOfFile:@"/tmp/google.png"];
    NSDate *date = [[NSDate alloc] initWithTimeIntervalSinceNow:1000];
    int integer = 1000;
    float flo = 3.14;
    bool boolean = true;
    
    // putting all the data types into the array
    NSArray *plistStuff = [[NSArray alloc] initWithObjects:array, dictionary, string, data, date, integer, flo, boolean, nil];
    
    // outputting data types in plistStuff into a plist
    [plistStuff writeToFile:@"/tmp/ch26Challenge.plist"
                 atomically:YES];
    
}
return 0;

}[/code]

I’m sure it’s something small. I appreciate any suggestions.


#2

[quote][code]

int integer = 1000;
float flo = 3.14;
bool boolean = true;

// putting all the data types into the array
NSArray *plistStuff = [[NSArray alloc] initWithObjects:array, dictionary, string, data, date, integer, flo, boolean, nil];

[/code][/quote]
Collection objects admit as members only objects that are instances of classes.

But integer, float, and boolean are fundamental types and thus can’t be added to collections directly. They must be wrapped inside NSNumber objects first.

[mod edit: typo flo->float, objects->types]


#3

Thanks for your help!