dark_perfect
dark_perfect

Reputation: 1478

Obj-C: Error trying to store indirect pointer as 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;

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:

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

How do I go about resolving this?

Upvotes: 1

Views: 178

Answers (1)

Nikolai Ruhe
Nikolai Ruhe

Reputation: 81868

  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.

Upvotes: 1

Related Questions