Ios 从另一个对象引用Objective-C类属性

Ios 从另一个对象引用Objective-C类属性,ios,cocoa,oop,nsobject,Ios,Cocoa,Oop,Nsobject,因此,我在Objective-C中遇到了这个问题。让我为这个问题设定一个阶段 我有一个约束,它不允许我修改对象的属性。因为它将断言我正在修改该对象,而没有将其置于写入和提交事务之间 ObjectA* constrainedObject = ...; // Retrieved from source with constraint applied. constrainedObject.name = @"John"; // Assert tripped [db writeTransaction];

因此,我在Objective-C中遇到了这个问题。让我为这个问题设定一个阶段

我有一个约束,它不允许我修改对象的属性。因为它将断言我正在修改该对象,而没有将其置于写入和提交事务之间

ObjectA* constrainedObject = ...; // Retrieved from source with constraint applied.
constrainedObject.name = @"John"; // Assert tripped
[db writeTransaction];
constrainedObject.name = @"John"; // Does not assert 
[db commitTransaction];
但是,如果创建一个新对象,我可以绕过此限制,通过将引用指定给
无约束对象来修改该对象

ObjectA* constrainedObject = ...; // Retrieved from source with constraint applied.
ObjectA* unconstrainedObject = [[ObjectA alloc] init];
unconstrainedObject.id = contrainedObject.id;
// Change name here
unconstrainedObject.name = @"John";
unconstrainedObject.home = @"Mansion";
unconstrainedObject.age = constrainedObject.age; // Keep old property

// This illustrates the problem.
// I still want to keep some of the properties of the old
// object but have to manually type it in.
因此,我的问题是如何从
constrainedObject
中检索所有属性引用,而不手动键入所有内容

是否有办法检查并将
NSObject
的键值属性映射到同一类型的另一个
NSObject


相关:

我很难理解。您能不能不简单地执行
ObjectA*unconstrainedObject=constrainedObject.copy?约束阻止了吗?复制引用了吗?指向对象的属性还是直接复制并指向内存中的新对象?也就是说,复制是否执行此对象a->property->a ObjectA b->property->a//对内存中对象a的相同引用a->property a ObjectA b->property b//对a的复制不是对浅或深的引用?复制是否创建深或浅的复制取决于
-copyWithZone:
(不看课程很难说,但我不确定这对你来说是否重要)。这也是手动属性映射完成的地方,它仍然需要键入所有内容,但至少在一个位置完成。