Using methods from non-ARC libraries in an ARC project?

随声附和 提交于 2019-12-08 07:37:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!