向"_unsafe_unretained id"类型的参数发送"NSString * _strong *",更改指针的保留/释放属性 [英] Sending "NSString *_strong*to parameter of type _unsafe_unretained id* "change retain/release properties of pointer

查看:107
本文介绍了向"_unsafe_unretained id"类型的参数发送"NSString * _strong *",更改指针的保留/释放属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出现以下错误

Sending "NSString *_strong*to parameter of type _unsafe_unretained id* "changes retain/release properties of pointer ...

在以下行中:[theDict getObjects:values andKeys:keys]; 我正在尝试将通讯录中的地址添加到我的应用中.有人可以向我解释它的抱怨吗?我认为这是ARC问题,可能与手动内存管理有关?但不确定如何解决.

in the following line: [theDict getObjects:values andKeys:keys]; Im trying to add an address from contacts to my app. Could someone explain to me what its complaining about? I think its an ARC issue, possibly to do with manual memory management? but im unsure how to fix it.

   - (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
  shouldContinueAfterSelectingPerson:(ABRecordRef)person
                            property:(ABPropertyID)property
                          identifier:(ABMultiValueIdentifier)identifier


 {
    if (property == kABPersonAddressProperty) {
    ABMultiValueRef multi = ABRecordCopyValue(person, property);

    NSArray *theArray = (__bridge id)ABMultiValueCopyArrayOfAllValues(multi);

    const NSUInteger theIndex = ABMultiValueGetIndexForIdentifier(multi, identifier);

    NSDictionary *theDict = [theArray objectAtIndex:theIndex];

    const NSUInteger theCount = [theDict count];

    NSString *keys[theCount];

    NSString *values[theCount];

    [theDict getObjects:values andKeys:keys]; <<<<<<<<< error here

    NSString *address;
    address = [NSString stringWithFormat:@"%@, %@, %@",
               [theDict objectForKey: (NSString *)kABPersonAddressStreetKey],
               [theDict objectForKey: (NSString *)kABPersonAddressZIPKey],
               [theDict objectForKey: (NSString *)kABPersonAddressCountryKey]];

    _town.text = address;

    [ self dismissModalViewControllerAnimated:YES ];

        return YES;
}
return YES;
 }

推荐答案

NSDictionary getObjects:andKeys的文档:显示为:

The docs for NSDictionary getObjects:andKeys: show it as:

- (void)getObjects:(id __unsafe_unretained [])objects andKeys:(id __unsafe_unretained [])keys

但是您传递的两个值是强大的NSString引用(默认情况下,本地变量和ivars是强大的.这就是为什么会出现ARC错误的原因.您的参数与预期的类型不匹配.

But the two values you are passing in are strong NSString references (local variables and ivars are strong by default. This is why there is the ARC error. Your parameters don't match the expected types.

更改:

NSString *keys[theCount];
NSString *values[theCount];

收件人:

NSString * __unsafe_unretained keys[theCount];
NSString * __unsafe_unretained values[theCount];

应该解决编译器问题.

此更改意味着数组中的所有对象均未安全保留.但是,只要"theDict"没有超出"keys"和"values"的范围,就可以了.

This change means that none of the objects in your arrays are safely retained. But as long as 'theDict' doesn't go out scope before 'keys' and 'values' then you will be OK.

这篇关于向"_unsafe_unretained id"类型的参数发送"NSString * _strong *",更改指针的保留/释放属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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