我可以在 Xcode 4 中删除 Core Data 动态生成的方法吗?

Posted

技术标签:

【中文标题】我可以在 Xcode 4 中删除 Core Data 动态生成的方法吗?【英文标题】:Can I delete Core Data's dynamically generated methods in Xcode 4? 【发布时间】:2011-04-29 18:56:33 【问题描述】:

Core Data 生成了这四种方法。我可以删除它们,因为它们是动态生成的,对吗?

@implementation User
// . . .
@dynamic authorizations;

- (void)addAuthorizationsObject:(NSManagedObject *)value     
    NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
    [self willChangeValueForKey:@"authorizations" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
    [[self primitiveValueForKey:@"authorizations"] addObject:value];
    [self didChangeValueForKey:@"authorizations" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
    [changedObjects release];


- (void)removeAuthorizationsObject:(NSManagedObject *)value 
    NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
    [self willChangeValueForKey:@"authorizations" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
    [[self primitiveValueForKey:@"authorizations"] removeObject:value];
    [self didChangeValueForKey:@"authorizations" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
    [changedObjects release];


- (void)addAuthorizations:(NSSet *)value     
    [self willChangeValueForKey:@"authorizations" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];
    [[self primitiveValueForKey:@"authorizations"] unionSet:value];
    [self didChangeValueForKey:@"authorizations" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];


- (void)removeAuthorizations:(NSSet *)value 
    [self willChangeValueForKey:@"authorizations" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value];
    [[self primitiveValueForKey:@"authorizations"] minusSet:value];
    [self didChangeValueForKey:@"authorizations" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value];

相关链接:

Core Data methods not in header file Xcode4: Different code generated for custom core data managed objects http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdAccessorMethods.html

【问题讨论】:

【参考方案1】:

是的,只要您离开@dynamic 命令,就会在运行时生成访问器。

【讨论】:

以上是关于我可以在 Xcode 4 中删除 Core Data 动态生成的方法吗?的主要内容,如果未能解决你的问题,请参考以下文章

Xcode gRPC-Core 错误:找不到“openssl_grpc/ssl.h”文件

Mac App Store Xcode 5 删除 Xcode 4

Xcode 4 Core Data:如何使用在数据模型编辑器中创建的获取属性

从 xcode 4 修改配置文件

在 xcode 4 中打开 xcode 3.2 VST 项目

Core Data 中的实体中的实体 - Xcode