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 Build a Diary App Using Core Data Understanding Core Data Defining our Data Model

Jonas Wang
Jonas Wang
10,048 Points

Two extra files were added when creating NSManagedObject subclass

When I created a NSManagedObject subclass for THDiaryEntry Model, it generated two extra files, THDiaryEntry+CoreDataProperties.h and TheDiaryEntry+CoreDataProperties.m. What should I do with these two files?

// // THDiaryEntry+CoreDataProperties.h // Diary

// Choose "Create NSManagedObject Subclass…" from the Core Data editor menu // to delete and recreate this implementation file for your updated model. //

import "THDiaryEntry.h"

NS_ASSUME_NONNULL_BEGIN

@interface THDiaryEntry (CoreDataProperties)

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

@end

NS_ASSUME_NONNULL_END

// // THDiaryEntry+CoreDataProperties.m // Diary // // Choose "Create NSManagedObject Subclass…" from the Core Data editor menu // to delete and recreate this implementation file for your updated model. //

import "THDiaryEntry+CoreDataProperties.h"

@implementation THDiaryEntry (CoreDataProperties)

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

@end

// // THDiaryEntry.h // Diary // // Created by Wang, Jonas on 10/11/15. // Copyright © 2015 Wang, Jonas. All rights reserved. //

import <Foundation/Foundation.h>

import <CoreData/CoreData.h>

NS_ASSUME_NONNULL_BEGIN

@interface THDiaryEntry : NSManagedObject

// Insert code here to declare functionality of your managed object subclass

@end

NS_ASSUME_NONNULL_END

import "THDiaryEntry+CoreDataProperties.h"

// // THDiaryEntry.h // Diary // // Created by Wang, Jonas on 10/11/15. // Copyright © 2015 Wang, Jonas. All rights reserved. //

import <Foundation/Foundation.h>

import <CoreData/CoreData.h>

NS_ASSUME_NONNULL_BEGIN

@interface THDiaryEntry : NSManagedObject

// Insert code here to declare functionality of your managed object subclass

@end

NS_ASSUME_NONNULL_END

import "THDiaryEntry+CoreDataProperties.h"

2 Answers

Jens Hagfeldt
Jens Hagfeldt
16,548 Points

Hi Zhuonan.

When creating subclasses out of your Core Data datamodel X-code automatically creates those two extra files and should do, so it not a problem. The first file "THDiaryEntry.h" is where you make your changes if you want to add any. The other file "THDiaryEntry+CoreDataProperties.h" is what Core Data itself manages, so you shall not make any changes in there. The same goes for the "THDiaryEntry.h" and "THDiaryEntry+CoreDataProperties.h" as well. If and when you make some changes to the "THDiaryEntry.h" by file for example, then when you build your project Core Data will update the "THDiaryEntry+CoreDataProperties.h" file to match your changes.

Hope this explanation made sense for you... Keep coding! / Jens

I have this problem too..