问题
I am using the excellent, however, non-ARC project: https://github.com/boredzo/iso-8601-date-formatter
I am trying to use the following method from this library which is non-ARC in an ARC project:
- (NSDate *) dateFromString:(NSString *)string timeZone:(out NSTimeZone **)outTimeZone;
I have tried:
group.updatedAt = [formatter dateFromString:someString timeZone:[NSTimeZone localTimeZone]];
group.updatedAt = [formatter dateFromString:someString timeZone:*__autorelease [NSTimeZone localTimeZone]];
group.updatedAt = [formatter dateFromString:someString timeZone:(*__autoreleasing [NSTimeZone localTimeZone]] *);
group.updatedAt = [formatter dateFromString:someString timeZone:[[NSTimeZone localTimeZone] autorelease]];
Note that I am fairly new to iOS, so I don't have any experience with memory management.
But with all these attempts, I received the following error message:
Implicit conversion of an Objective-C pointer to 'NSTimeZone *__autoreleasing *' is disallowed with ARC
So how do I use a non-ARC library's methods in an ARC Project?
回答1:
The NSTimeZone is an output parameter, so you need to pass a pointer to a pointer, like this:
NSTimeZone *theTimeZone = nil;
group.updatedAt = [formatter dateFromString:someString timeZone:&theTimeZone];
When the function returns, theTimeZone will be set to the output value of the function.
来源:https://stackoverflow.com/questions/16492931/using-methods-from-non-arc-libraries-in-an-arc-project