1

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?

Nikolai Ruhe
  • 81,520
  • 17
  • 180
  • 200
dark_perfect
  • 1,458
  • 1
  • 23
  • 41

1 Answers1

1
  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.
Nikolai Ruhe
  • 81,520
  • 17
  • 180
  • 200
  • Ah ha! Thanks! I didn't know you could put ownership qualifiers between the asterisks like that. I don't have much say over the design and architecture (the lead is fairly stubborn), and there are several architectural issues that I disagree with on this project, but thank you for your advice. – dark_perfect Mar 05 '12 at 20:25
  • No, you really should not do this. The design is so utterly broken, you should confront the person who's proposing this. At least point him to this reply. – Nikolai Ruhe Mar 06 '12 at 02:52