使用ARC项目中的非ARC库的方法? [英] Using methods from non-ARC libraries in an ARC project?

查看:100
本文介绍了使用ARC项目中的非ARC库的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是非常好的非ARC项目: https:// github .com / boredzo / iso-8601-date-formatter

I am using the excellent, however, non-ARC project: https://github.com/boredzo/iso-8601-date-formatter

我试图从ARC中的非ARC中使用以下方法项目:

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;

我试过:

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]];

注意,我是iOS的新手,所以我没有任何内存管理经验。

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

隐式转换Objective-C指针为NSTimeZone * __ autoreleasing * 那么如何在ARC项目中使用非ARC库的方法?

So how do I use a non-ARC library's methods in an ARC Project?

推荐答案

code> NSTimeZone 是一个输出参数,因此您需要传递一个指针,如下所示:

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];

当函数返回时, theTimeZone 设置为函数的输出值。

When the function returns, theTimeZone will be set to the output value of the function.

这篇关于使用ARC项目中的非ARC库的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆