-(NSData *)jsonRepresentation:(NSError **error)error {
NSDictionary *dict = [self getDictRepresentation];
return [NSJSONSerialization dataWithJSONObject:dict options:nil error:error];
}
// Some other place...
NSError *__autoreleasing error = nil;
NSData *json = [obj jsonRepresentation:&error];
自動釋放語義安全地傳達error
堆棧到我的第二個代碼塊嗎?下面的iOS代碼是否安全? (__autoreleasing語義)
那些自動釋放機制實際上隱含在局部變量中(有一些例外),並且不需要明確說明。但是,是的,這是正確的。 – 2013-03-18 21:20:53
@ RichardJ.RossIII:你是什麼意思?除非另有說明,obj-c類型的局部變量默認爲'__strong'。 – 2013-03-18 21:26:11
@KevinBallard我的意思是說,它們的行爲就像是一個自動釋放值,只要它們可以延長聲明塊的生命週期。返回值特別是變成__autoreleasing(除非你指定了另一個返回類型屬性)。在極少數情況下,__autoreleasing真的需要。 – 2013-03-18 21:28:46