开发者

for Xcode produced Core Data managed objects, do I need to add a dealloc method to release variables?

for Xcode produced Core Data managed objects, do I need to add a dea开发者_开发知识库lloc method to release variables?

So when I have a core data model for my iPhone app, and I let XCode generate the managed object classes, I note there is no dealloc method. Do I need to "release" in a dealloc method myself manually to the variables/properties?

I see the code-generated managed object classes have:

  • the property is marked "retain" in the header file
  • in the implementation file it is set up with "@dynamic" (i.e. not @sythesise)

thanks


You don't need to (and shouldn't) modify these generated files. The @dynamic means that the property implementations will be provided at runtime. Dynamic Properties


There's two parts to this. For the attributes that you define in you're model, don't release them in a dealloc method. Core Data is managing those for you. But if you add other ivars to the class that gets generated, say you have an imageData attribute and then make a UIImage out of it that you hold in your NSManagedObject subclass, then you need to add the dealloc method and release it like you would in any other object.

I'd highly recommend you start using mogenerator. It's nice since it generates a machine file and a user file to keep the stuff that's handled automatically for you separate from your custom code.


While you do not need to release Core Data managed properties, you should clean up any properties or instance variables your custom Core Data subclass creates. However, you cannot rely on dealloc to be called on Core Data subclasses. Use willTurnIntoFault to perform any cleanup necessary.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜