ARC禁止Objective-Cstruct
s或union
s中的對象s。使用ARC時用於Objective-C對象而不是結構的是什麼?
除非你添加__unsafe_unretained
這意味着它沒有管理。
我想知道現在人們用什麼來代替struct
?
或者您是否手動保留所有內容?
ARC禁止Objective-Cstruct
s或union
s中的對象s。使用ARC時用於Objective-C對象而不是結構的是什麼?
除非你添加__unsafe_unretained
這意味着它沒有管理。
我想知道現在人們用什麼來代替struct
?
或者您是否手動保留所有內容?
我管理一個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
這很簡單 - 如果你想添加一個對象結構內,你做錯了。無論何時您需要一個結構來存放一個obj-c對象,都可以將該結構轉換爲一個obj-c對象。
旁邊,當你正在包裝一個objC庫到C ... – 2015-03-04 01:03:41
我回答到這裏https://stackoverflow.com/a/28845377/1570826
也許有人用正確的水平可能標誌着本或其他爲重複。
實現一個靜態類並僞造它的屬性會不會容易很多,如here?
請添加一些示例代碼,你的問題 – 2013-05-02 08:10:59
的可能重複[typedef結構主場迎戰對象 - 效益(http://stackoverflow.com/questions/15358771/typedef-struct-vs-object-benefits) – Sulthan 2013-05-02 08:12:02
的結構vs對象問題是關於在哪種情況下使用的抽象討論。這是一個關於你將使用什麼來代替stu的問題,因爲arc不允許工程包含Objective C對象。 PPl建議不要使用Objective C Objects並仍然使用結構。做ppl只是使用對象?或者還有其他一些我不知道的方法。 – abe 2013-05-02 08:19:49