Getting Errors and not building


I am working through the book and so far have only encountered problems I have been able to overcome. On page 333 we are asked to compare assetType to item AssetType (assetType == [item assetType] which generates a warning: Comparison of distinct pointer types (NSManagedObject *) and (BNRItem *). Then later in the next method we are asked to [item setAssetType:assetType] which is generating a warning : incompatible pointer types sending ‘NSManagedObject *__strong’ to parameter of type ‘BNRAssetType *’ which also seems bad. And lastly - in viewWillAppear in DetailViewController.m NSString *typeLabel = [[item assetType] valueForKey:@“label”]; which gives an ARC issue: error: receiver type ‘BNRAssetType’ for instance message is a forward declaration. All this leads me to think that I have made some very basic mistakes - like not including a header file or something, but I can’t figure out where and what I have done wrong. Any thoughts would be appreciated…


Paste your .h and .m for BNRItem. It sounds like perhaps you generated the class files for BNRAssetType when you shouldn’t have, but I’m not sure.



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

@class BNRAssetType;

@interface BNRItem : NSManagedObject

@property (nonatomic) NSTimeInterval dateCreated;
@property (nonatomic, retain) NSString * imageKey;
@property (nonatomic, retain) NSString * itemName;
@property (nonatomic) double orderingValue;
@property (nonatomic, retain) NSString * serialNumber;
@property (nonatomic, strong) UIImage *thumbnail;
@property (nonatomic, retain) NSData * thumbnailData;
@property (nonatomic) int32_t valueInDollars;
@property (nonatomic, retain) BNRAssetType *assetType;

-(void)setThumbnailDataFromImage:(UIImage *)image;



[code]#import “BNRItem.h”

@implementation BNRItem

@dynamic dateCreated;
@dynamic imageKey;
@dynamic itemName;
@dynamic orderingValue;
@dynamic serialNumber;
@dynamic thumbnail;
@dynamic thumbnailData;
@dynamic valueInDollars;
@dynamic assetType;

-(void)setThumbnailDataFromImage:(UIImage *)image {
CGSize origImageSize = [image size];
CGRect newRect = CGRectMake(0, 0, 40, 40);
float ratio = MAX(newRect.size.width/origImageSize.width, newRect.size.height/origImageSize.height);
UIGraphicsBeginImageContextWithOptions(newRect.size, NO, 0.0);
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:newRect cornerRadius:5.0];
[path addClip];
CGRect projectRect;
projectRect.size.width = ratio * origImageSize.width;
projectRect.size.height = ratio * origImageSize.height;
projectRect.origin.x = (newRect.size.width - projectRect.size.width)/2.0;
projectRect.origin.y = (newRect.size.height - projectRect.size.height)/2.0;
[image drawInRect:projectRect];
UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();
[self setThumbnail:smallImage];
NSData *data = UIImagePNGRepresentation(smallImage);
[self setThumbnailData:data];

[super awakeFromFetch];
UIImage *tn = [UIImage imageWithData:[self thumbnailData]];
[self setPrimitiveValue:tn forKey:@“thumbnail”];

-(void)awakeFromInsert {
[super awakeFromInsert];
NSTimeInterval t = [[NSDate date] timeIntervalSinceReferenceDate];
[self setDateCreated:t];

Thank you! I hate moving on when something isn’t working!


Ah, I see. It looks like you generated the .h and .m files for BNRAssetType, too. In this exercise, we opted to keep BNRAssetType a standard NSManagedObject instead of creating a special subclass (because the BNRASsetType just holds data and doesn’t do anything interesting).

Remove the @class BNRAssetType from this file. Change the assetType property’s type to NSManagedObject *. In your xcdatamodeld file, select the BNRAssetType entity and delete its “Class” field in the inspector. You’ll have to delete the app from your simulator/device before running again.


Thank you! I just did that before coming back to the forum - I looked at the example BNRItem files in the project files in chapter 16. Yippee! Onward! And thank you again for taking the time to look at and respond to the posts on here!