ARC forbids synthesizing a property with unspecified ownership or storage

12,590

Solution 1

Change your property declaration to:

@property (nonatomic,strong) UIColor *color;

so that ARC knows it should be retained. This would have compiled without strong before ARC but it would be dangerous since the default was assign and the color would have been released unless it was retained elsewhere.

I would highly recommend the WWDC2011 video about ARC.

Solution 2

You have to specify either strong or weak storage in the property declaration (next to nonatomic).

Share:
12,590
William Sham
Author by

William Sham

Updated on June 16, 2022

Comments

  • William Sham
    William Sham almost 2 years

    I've created a @property of UIColor,

    @property (nonatomic) UIColor *color;
    

    and then I tried to synthesize it:

    @synthesize color = _color;
    

    but I receive an error:

    ARC forbids synthesizing a property of Objective-C object with unspecified ownership or storage attribute

    What does that mean?

    All I'm trying to do is to create a property for a UIColor object which changes color.

  • Kekoa
    Kekoa over 11 years
    @WilliamSham you don't need to do it for all pointers, only for properties. Pointers in the local scope are strong references by default, but you can instruct ARC to treat a pointer as a weak reference by using __weak.
  • Vikram Rao
    Vikram Rao almost 10 years
    This is not required unless the property is a block in which case it has to be explicitly mentioned as copy. So the issue is something else.
  • Vikram Rao
    Vikram Rao almost 10 years
    @JoePasq Not required to specify storage always. Check my comments in other answers and question.
  • Brian
    Brian almost 10 years
    @VikramRao, this question is 2.5 years old. At the time that it was asked, synthesized properties were required to declare the storage class and the default was assign
  • Nat
    Nat about 9 years
    @Brian Anyway, it'd be good to update your accepted answer, as people may see it via google. These devs, who don't know it, may think they need to write it explicitly. As for now this error is shown mostly with blocks, which needs to be copy. Objects are by default strong, primitive types like BOOL, NSInteger etc - assign and it's unlikely anyone can see this error with objects/primitive types.
  • Mecki
    Mecki almost 9 years
    @Vive Actually you don't need to declare blocks copy anymore - it's fine to declare them strong now. If the block has already been copied to the heap, copy has always behaved like strong (both just retained the block). If the block was still on stack though, copy used to copy it to heap while strong used to do nothing. The LLVM developers considered that a bug, regardless what Apple's documentation said and now strong behaves like copy if the block is on stack, just like copy behaves like strong if it's on heap - IOW it makes no difference anymore, only weak does.
  • Mecki
    Mecki almost 9 years
    @Brian Even at the time it was asked, your answer has still been wrong. It's true, the default prior to ARC used to be assign, but no storage class was required as if it was required, there would not have been a default at all. Default means "unless I say something else, take this". Not giving a storage class created an assign property. Maybe not what you wanted, but the compiler did not throw an error because of that. Why would applying default behavior be erroneous?
  • Brian
    Brian almost 9 years
    @Mecki, my answer was correct, but yeah my comment about required/default doesn't really make sense
  • Nat
    Nat almost 9 years
    @Brian You're right, I've just checked developer.apple.com/library/ios/releasenotes/ObjectiveC/… and found section: How do blocks work in ARC? Blocks “just work” when you pass blocks up the stack in ARC mode, such as in a return. You don’t have to call Block Copy any more.. Thank you for the useful information, didn't notice it.
  • Markus
    Markus over 8 years
    As @VikramRao mentioned, when you are specifiing block as a property, you have to explicitly put copy.. Thank you for this hint, should be highlighted more..