Challenge 26 getting ERROR need help


#1

[code]//
// main.m
// Challange 26
//
// Created by Doug McBrierty on 5/22/13.
// Copyright © 2013 D. B, McBrierty, Inc. All rights reserved.
//

#import <Foundation/Foundation.h>

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

@autoreleasepool {
    
    NSMutableArray *parts = [[NSMutableArray alloc] init];
    
    NSMutableDictionary *part;
    
    part = [NSMutableDictionary dictionary];
    [part setObject:@"AR-123"
              forKey:@"partNo"];
 
    // this can be just the string @:"Wing Nut"
    NSString *pdesc = @"Wing Nut";
    [part setObject:pdesc
             forKey:@"Description"];
    NSData *WNModelData = [NSData dataWithContentsOfFile:@"/tmp/PartWNModel.rtf"];
    [part setObject:WNModelData
             forKey:@"Model No"];
    [part setObject:[NSNumber numberWithFloat:5.75]
             forKey:@"UnitPrice"];
    [part setObject:@"Each"
             forKey:@"Unit of Measure"];
    [part setObject:[NSNumber numberWithInt:20]
              forKey:@"ReOrdQty"];
    [part setObject:[NSNumber numberWithInt:10]
             forKey:@"OnHandQty"];
    [part setObject:[NSDate dateWithNaturalLanguageString:@"May 22, 2013"]
             forKey:@"DateLastSale"];
    [part setObject:[NSNumber numberWithBool:NO]
             forKey:@"AutoReOrder"];
    [parts addObject:part];
    
    part = [NSMutableDictionary dictionary];
    [part setObject:@"AL-345"
             forKey:@"partNo"];
    
    pdesc = @"Rivet";
    [part setObject:pdesc
             forKey:@"Description"];

// solution was to remove this NSData statement and re-use the “WNModelData” variable
// NSData *rvModelData = [NSData dataWithContentsOfFile:@"/tmp/PartRvModel.rtf"];
// [part setObject:rvModelData ///<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< getting data 0X0000000000000 error file is in tmp and spelling is correct, if I comment out other NSData it does not works??
//
[part setObject:WNModelData
forKey:@“Model No”];[/color]
[part setObject:[NSNumber numberWithFloat:3.50]
forKey:@“UnitPrice”];
[part setObject:@"Each"
forKey:@“Unit of Measure”];
[part setObject:[NSNumber numberWithInt:2000]
forKey:@“ReOrdQty”];
[part setObject:[NSNumber numberWithInt:175]
forKey:@“OnHandQty”];
[part setObject:[NSDate dateWithNaturalLanguageString:@“May 10, 2013”]
forKey:@“DateLastSale”];
[part setObject:[NSNumber numberWithBool:YES]
forKey:@“AutoReOrder”];

    [parts addObject:part];
    
    [parts writeToFile:@"/tmp/partslist.plist"
             atomically:YES];

    
}
return 0;

}[/code]


#2

Well I got the program to work by changing the design for one NSData file and reused the WNModelData variable. I do not under stand why I could not define two different NSData variables. Hopefully I will learn that in future chapters. Could not find any info on what type data should be in the file.

Love this book I am learning Objective-C. Have been programming for ver 40 years this is a new language in many ways. I love the feel of the language as I write it.

Thanks Doug McBrierty


#3

Are you sure both files, /tmp/PartWNModel.rtf and /tmp/PartRvModel.rtf, exist?

I built your code and ran it; I got no errors after creating both files.

Try creating the files from the command line:

touch /tmp/PartWNModel.rtf touch /tmp/PartRvModel.rtf


#4

Thank You it was the file I created them with an app called Text Editor. So recreated them with TextEdit and the following code worked.
I am still confused about NSData data types, but I will find an explanation soon
Thank You for your help.
Doug

//
//  main.m
//  Challange 26
//
//  Created by Doug McBrierty on 5/22/13.
//  Copyright (c) 2013 D. B, McBrierty, Inc. All rights reserved.
//

#import <Foundation/Foundation.h>

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

    @autoreleasepool {
        
        NSMutableArray *parts = [[NSMutableArray alloc] init];
        
        NSMutableDictionary *part;
        
        part = [NSMutableDictionary dictionary];
        [part setObject:@"AR-123"
                  forKey:@"partNo"];
     
        NSData *WNModelData = [NSData dataWithContentsOfFile:@"/tmp/PartWNModel.rtf"];
        NSData *rvModelData = [NSData dataWithContentsOfFile:@"/tmp/PartRvModel.rtf"];

        
        // this can be just the string @:"Wing Nut"
        NSString *pdesc = @"Wing Nut";
        [part setObject:pdesc
                 forKey:@"Description"];
        [part setObject:WNModelData
                 forKey:@"Model No"];
        [part setObject:[NSNumber numberWithFloat:5.75]
                 forKey:@"UnitPrice"];
        [part setObject:@"Each"
                 forKey:@"Unit of Measure"];
        [part setObject:[NSNumber numberWithInt:20]
                  forKey:@"ReOrdQty"];
        [part setObject:[NSNumber numberWithInt:10]
                 forKey:@"OnHandQty"];
        [part setObject:[NSDate dateWithNaturalLanguageString:@"May 22, 2013"]
                 forKey:@"DateLastSale"];
        [part setObject:[NSNumber numberWithBool:NO]
                 forKey:@"AutoReOrder"];
        [parts addObject:part];
        
        part = [NSMutableDictionary dictionary];
        [part setObject:@"AL-345"
                 forKey:@"partNo"];
        
        pdesc = @"Rivet";
        [part setObject:pdesc
                 forKey:@"Description"];
        
        [part setObject:rvModelData
                 forKey:@"Model No"];
        [part setObject:[NSNumber numberWithFloat:3.50]
                 forKey:@"UnitPrice"];
        [part setObject:@"Each"
                 forKey:@"Unit of Measure"];
        [part setObject:[NSNumber numberWithInt:2000]
                 forKey:@"ReOrdQty"];
        [part setObject:[NSNumber numberWithInt:175]
                 forKey:@"OnHandQty"];
        [part setObject:[NSDate dateWithNaturalLanguageString:@"May 10, 2013"]
                 forKey:@"DateLastSale"];
        [part setObject:[NSNumber numberWithBool:YES]
                 forKey:@"AutoReOrder"];

        [parts addObject:part];
        
        [parts writeToFile:@"/tmp/partslist.plist"
                 atomically:YES];

        
    }
    return 0;
}