Why I get error "Cannot synthesize weak property in file using manual reference counting" when defining delegate?

11,858

Solution 1

you don't have to have to use synthesize since Xcode 4.4 and LLVM 2.0 the compiler makes the synthesize automatically. you can remove the line

 @synthesize delegate; 

if you want to make the synthesize manually you can turn on "implicit synthesized properties" flag in your build settings by set it to YES

and you are using manual retain release you can't use weak/strong in your properties you should use retain/assign .

Solution 2

You need to set Weak References in Manual Retain Release to YES in your Apple LLVM 8.0 - Language - Objective C under Build Settings of your project, as shown below in screenshot-

enter image description here

Share:
11,858
Chen Li Yong
Author by

Chen Li Yong

Currently, I'm a mainly mobile programmer (iOS, swift / obj-C) which currently lead and work in multiple projects.

Updated on June 27, 2022

Comments

  • Chen Li Yong
    Chen Li Yong almost 2 years

    I have protocol and class header in one file:

    @protocol SomethingDelegate
    - (void) doSomething;
    @end
    
    @interface SomethingClass
    @property (nonatomic, weak) id <SomethingDelegate> delegate;
    @end
    

    On the .m file:

    @implementation SomethingClass // in here I got error "Cannot synthesize weak property in file using manual reference counting"
    
    @end
    

    If I change it into like this:

    @implementation SomethingClass 
    
    @synthesize delegate; // in here I got error "Cannot synthesize weak property in file using manual reference counting"
    
    @end
    

    Why is this happened? And how to fix this? The error disappear if I change from weak to strong. But that's not how delegate should be declared, right? How to properly declare a weak delegate?