ARC forbids Objective-C objects in struct
s or union
s.
Unless you add __unsafe_unretained
which means its not managed.
I was wonder what people are using in place of struct
s now if anything?
Or are you retaining everything manually?
ARC forbids Objective-C objects in struct
s or union
s.
Unless you add __unsafe_unretained
which means its not managed.
I was wonder what people are using in place of struct
s now if anything?
Or are you retaining everything manually?
It's very simple - if you want to add an object inside a struct, you are doing it wrong. Whenever you need a struct to hold an obj-c object, convert the struct into an obj-c object.
I would manage different objects in one objc-object like this:
@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
I answered to it here https://stackoverflow.com/a/28845377/1570826
maybe somebody with the right level could mark this or the other as a duplicate.