Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

-[DiaryEntry imageData]: unrecognized selector sent to instance 0x7fca484852a0

Rather confused about whats happening here, I am not sure why i am getting this error, my imageData is declared in the DiaryEntry.h and implemetented in the .m file. for some reason it tells me this when i run my app.

-[DiaryEntry imageData]: unrecognized selector sent to instance 0x7fca484852a0

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DiaryEntry imageData]: unrecognized selector sent to instance 0x7fca484852a0'

i added break point to see whats happeing and it always stops the if statement.

if(entry.imageData) {
        self.mainImageView.image = [UIImage imageWithData:entry.imageData];

    }else {
       self.mainImageView.image = [UIImage imageNamed:@"icn_noimage"];
    }

havent seen anyone else with this so i am not sure what i have done wrong? just end ups

int main(int argc, char * argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 
    }
}

Thread 1:EXC_BAD_INSTRUCTION(code=EXC_1386_INVOP, subcode=0x0)

any advice

13 Answers

Sounds weird but this has helped me in the same situation:

Open the simulator (or your real device) and go to the home screen. Delete the app. Build and run again. Changes to the data model file require a fresh start or migration code.

In your core data model, is imageData correctly specified as NSData?

Also don't forget to set the class name in the data model. All in the core data settings

And if all else fails, click on the Product top menu and select Clean. Then try again.

No worries. This is where you click on the core data model file itself in the left pane and the model should open up in a graphical edit screen. I'm assuming you have already created the model file.

Are you sure you have imported the DiaryEntry.h file?

yeah its all there? should there be something else?

#import "EntryCell.h"
#import "DiaryEntry.h"

@interface EntryCell ()
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UILabel *bodyLabel;

@property (weak, nonatomic) IBOutlet UILabel *locationLabel;
@property (weak, nonatomic) IBOutlet UIImageView *mainImageView;
@property (weak, nonatomic) IBOutlet UIImageView *moodImageView;

@end

@implementation EntryCell

+(CGFloat)heightForEntry:(DiaryEntry *)entry {

    const CGFloat topMargin = 35.0f;
    const CGFloat botttomMargin = 80.0f;
    const CGFloat minHeight = 106.0f;

    UIFont *font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
    CGRect boundingBox = [entry.body boundingRectWithSize: CGSizeMake(210, CGFLOAT_MAX) options:(NSStringDrawingUsesFontLeading |NSStringDrawingUsesLineFragmentOrigin)attributes:@{NSFontAttributeName: font} context:nil];

    return MAX(minHeight, CGRectGetHeight(boundingBox) + topMargin + botttomMargin);
}

- (void)configureCellForEntry:(DiaryEntry *)entry {
    self.bodyLabel.text = entry.body;
    self.locationLabel.text = entry.location;

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"EEEE, MMMMM d yyyy"];

    NSDate *date = [NSDate dateWithTimeIntervalSince1970:entry.date];

    self.dateLabel.text = [dateFormatter stringFromDate:date];

    if(!entry.imageData){
        self.mainImageView.image = [UIImage imageWithData:entry.imageData];

    }else {
       self.mainImageView.image = [UIImage imageNamed:@"icn_noimage"];
    }

    if(entry.mood == DiaryEntryMoodGood){
        self.moodImageView.image = [UIImage imageNamed:@"icn_happy"];

    }else if (entry.mood == DiaryEntryMoodAverage) {
        self.moodImageView.image = [UIImage imageNamed:@"icn_average"];

    } else if (entry.mood == DiaryEntryMoodBad) {
        self.moodImageView.image = [UIImage imageNamed:@"icon_bad"];

    }
}

@end

could you also copy and paste your DiaryEntry.h and .m files?

DiaryEntry.h

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>


NS_ENUM(int16_t, DiaryEntryMood) {
    DiaryEntryMoodGood = 0,
    DiaryEntryMoodAverage =1,
    DiaryEntryMoodBad = 2

};

@interface DiaryEntry : NSManagedObject

@property (nonatomic) NSTimeInterval date;
@property (nonatomic, retain) NSString * body;
@property (nonatomic, retain) NSData * imageData;
@property (nonatomic) int16_t mood;
@property (nonatomic, retain) NSString * location;


@property(nonatomic, readonly) NSString *sectionName;

@end

DiaryEntry.m

#import "DiaryEntry.h"


@implementation DiaryEntry

@dynamic date;
@dynamic body;
@dynamic imageData;
@dynamic mood;
@dynamic location;

-(NSString *)sectionName {

    NSDate *date = [NSDate dateWithTimeIntervalSinceNow:self.date];

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

    [dateFormatter setDateFormat:@"MMM yyyy"];

    return [dateFormatter stringFromDate:date];
}

@end

I have only declared imageData as NSData @property in my DiaryEntry.h file, is there another file i am missing?

Where would i find the Core Data Model where i can make those adjustments?

Thanks for this man really appreciating the help. (had no idea that clean function was even there)

yeah its there but imageData = Binary Data was
image = Binary Data

now that i changed it to imageData i get an error haha

CoreDataStack.m Thread 1: signal SIGABRT at the abort

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
    // The persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it.
    if (_persistentStoreCoordinator != nil) {
        return _persistentStoreCoordinator;
    }

    // Create the coordinator and store

    _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Diary.sqlite"];
    NSError *error = nil;
    NSString *failureReason = @"There was an error creating or loading the application's saved data.";
    if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
        // Report any error we got.
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        dict[NSLocalizedDescriptionKey] = @"Failed to initialize the application's saved data";
        dict[NSLocalizedFailureReasonErrorKey] = failureReason;
        dict[NSUnderlyingErrorKey] = error;
        error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:9999 userInfo:dict];
        // Replace this with code to handle the error appropriately.
        // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }

    return _persistentStoreCoordinator;
}

when i remove it the application runs without any of the data showing gives me the same

int main(int argc, char * argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 
    }
}

Thread 1:EXC_BAD_INSTRUCTION(code=EXC_1386_INVOP, subcode=0x0)

My console reads

2015-01-05 23:19:31.934 Diary[6240:282246] file:///Users/Klish3/Library/Developer/CoreSimulator/Devices/C2F3C271-8E8A-4ED2-A1D7-F144823775A1/data/Containers/Data/Application/9F547FD8-6736-47ED-BD21-A1791BE3CE99/Documents/ 2015-01-05 23:19:32.003 Diary[6240:282246] CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///Users/Klish3/Library/Developer/CoreSimulator/Devices/C2F3C271-8E8A-4ED2-A1D7-F144823775A1/data/Containers/Data/Application/9F547FD8-6736-47ED-BD21-A1791BE3CE99/Documents/Diary.sqlite options:(null) ... returned error Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed. (Cocoa error 134100.)" UserInfo=0x7fce81d55510 {metadata={ NSPersistenceFrameworkVersion = 519; NSStoreModelVersionHashes = { DiaryEntry = <af46a5fb 924f9be9 7c76a50a 497fecbe e40359d5 98625f89 0d835309 ca95149e>; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite; NSStoreUUID = "82C39F9F-FA32-44E0-A228-CE019835DA14"; "_NSAutoVacuumLevel" = 2; }, reason=The model used to open the store is incompatible with the one used to create the store} with userInfo dictionary { metadata = { NSPersistenceFrameworkVersion = 519; NSStoreModelVersionHashes = { DiaryEntry = <af46a5fb 924f9be9 7c76a50a 497fecbe e40359d5 98625f89 0d835309 ca95149e>; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite; NSStoreUUID = "82C39F9F-FA32-44E0-A228-CE019835DA14"; "_NSAutoVacuumLevel" = 2; }; reason = "The model used to open the store is incompatible with the one used to create the store"; } 2015-01-05 23:19:32.004 Diary[6240:282246] Unresolved error Error Domain=YOUR_ERROR_DOMAIN Code=9999 "Failed to initialize the application's saved data" UserInfo=0x7fce81d56fb0 {NSLocalizedFailureReason=There was an error creating or loading the application's saved data., NSLocalizedDescription=Failed to initialize the application's saved data, NSUnderlyingError=0x7fce81d55590 "The operation couldn’t be completed. (Cocoa error 134100.)"}, { NSLocalizedDescription = "Failed to initialize the application's saved data"; NSLocalizedFailureReason = "There was an error creating or loading the application's saved data."; NSUnderlyingError = "Error Domain=NSCocoaErrorDomain Code=134100 \"The operation couldn\U2019t be completed. (Cocoa error 134100.)\" UserInfo=0x7fce81d55510 {metadata={\n NSPersistenceFrameworkVersion = 519;\n NSStoreModelVersionHashes = {\n DiaryEntry = <af46a5fb 924f9be9 7c76a50a 497fecbe e40359d5 98625f89 0d835309 ca95149e>;\n };\n NSStoreModelVersionHashesVersion = 3;\n NSStoreModelVersionIdentifiers = (\n \"\"\n );\n NSStoreType = SQLite;\n NSStoreUUID = \"82C39F9F-FA32-44E0-A228-CE019835DA14\";\n \"_NSAutoVacuumLevel\" = 2;\n}, reason=The model used to open the store is incompatible with the one used to create the store}"; }

Thanks bro everything running smooth...

your a champion

I am an instance of the NSChampion class.

Lol