Obj-C:尝试将间接指针存储为iVar时出错 [英] Obj-C: Error trying to store indirect pointer as iVar

查看:82
本文介绍了Obj-C:尝试将间接指针存储为iVar时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人要求我创建一个具有类似于以下特征的方法:

I have been asked to create a method with a signature that resembles this:

- (void)updateLocation:(CLLocation**)location atInterval:(NSTimeInterval)interval untilDate:(NSDate*)finishDate;

这个想法是让用户传入我从类中更新的变量的地址.因此,我需要将location参数存储为iVar,只有当我尝试创建iVar时,我才会收到错误消息:

The idea is that a user passes in the address of a variable that I update from my class. So, I need to store the location argument as an iVar, only when I try to create the iVar, I receive the error:

指向没有明确所有权的非常量类型"CLLocation *"的指针.

Pointer to non-const type 'CLLocation *' with no explicit ownership.

我该如何解决这个问题?

How do I go about resolving this?

推荐答案

  1. 不要这样做.
  2. 问题出在自动引用计数中:ARC需要知道指针的所有权语义.解决方案:使参数和实例变量的类型为CLLocation * __strong *.
  3. 再次,不要!提议的体系结构破坏了封装,应视为不良设计而被拒绝.请改用委派或通知.
  1. Don't do this.
  2. The problem is in automatic reference counting: ARC needs to know ownership semantics of the pointee. Solution: Make argument's and instance variable's type CLLocation * __strong *.
  3. Again, don't! The proposed architecture breaks encapsulation and should be rejected as bad design. Use delegation or notifications instead.

这篇关于Obj-C:尝试将间接指针存储为iVar时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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