arc禁止在struct
s或union
s中使用objective-c对象。
除非您添加__unsafe_unretained
这意味着它不受管理。
我想知道现在人们用什么来代替“抄送”?
还是手动保存?
最佳答案
我将在一个objc对象中管理不同的对象,如下所示:
@class MyFirst, MySecond;
@interface MyContainer : NSObject
@property (nonatomic, strong, readonly) MyFirst *firstInst;
@property (nonatomic, strong, readonly) MySecond *secondInst;
// optional: convenience initializer
+ (instancetype)containerWithFirstInst:(MyFirst *)firstInst secondInst:(MySecond *)secondInst;
@end
// required by linker: stub definition for the class declared above
@implementation MyContainer
@end
@interface SomeController : NSObject
- (void)doSomething;
@end
@implementation SomeController
- (void)doSomething {
MyFirst *firstInstance = [[MyFirst alloc] initWithSomeParameters:...];
MySecond *secondInstance = [[MySecond alloc] initWithSomeParameters:...];
MyContainer *container = [MyContainer containerWithFirstInst:firstInstance secondInst:secondInstance];
// use container as a struct (but it's definitely an object that is managed by ARC)
}
@end