Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ARC and weak IBOutlet properties

I just updated a project to make use of ARC with the Xcode 4.2 built-in conversion tool. Unfortunately there is a weird bug appearing that I don't understand and didn't find anything about. I have a document class with a property declaration:

@property (weak) IBOutlet WebView *webView;

In the implementation file I have a @synthesize statement:

@synthesize webView=_webView;

When I try to compile it, it fails and tells me:

error: @synthesize of 'weak' property is only allowed in ARC or GC mode

Of course the project is tagged to compile with ARC. I would highly appreciate any help to understand what I'm doing wrong and why.

Edit: Was late yesterday. So here is a more complete compile-log:

[...] -fobjc-arc -Wno-trigraphs -fpascal-strings -O0 -Wmissing-prototypes -Wreturn-type -Wparentheses -Wswitch -Wno-unused-parameter -Wunused-variable -Wunused-value -Wshorten-64-to-32 -DDEBUG=1 -isysroot /Developer/SDKs/MacOSX10.7.sdk -fasm-blocks -mmacosx-version-min=10.7 -gdwarf-2 -Wno-sign-conversion "-DIBOutlet=attribute((iboutlet))" "-DIBOutletCollection(ClassName)=attribute((iboutletcollection(ClassName)))" "-DIBAction=void)attribute((ibaction)" -iquote [...]/Build/Intermediates/[...].build/Debug/[...].build/[...]-generated-files.hmap -I[...]/Build/Intermediates/[...].build/Debug/[...].build/[...]-own-target-headers.hmap -I[...]/Build/Intermediates/[...].build/Debug/[...].build/[...]-all-target-headers.hmap -iquote [...]/Build/Intermediates/[...].build/Debug/[...].build/[...]-project-headers.hmap -I[...]/Build/Products/Debug/include -I[...]/Build/Intermediates/[...].build/Debug/[...].build/DerivedSources/x86_64 -I[...]/Build/Intermediates/[...].build/Debug/[...].build/DerivedSources -F[...]/Build/Products/Debug -fno-objc-arc [...]

It seems the compiler-settings for ARC are turned on in the beginning and turned off again later in the arguments list. To be honest: I don't know where to remove such weird settings and how it came to this. The only solution I would come up with now, would be to start the complete project over from a blank and new one and import all the class files from scratch.

If someone knows an easier way, I would appreciate very much.

PS: I do have all build-settings concerning the ARC set to YES.

like image 355
Jacque Avatar asked Oct 15 '11 19:10

Jacque


People also ask

Should IBOutlet be weak or strong?

The official answer from Apple is that IBOutlets should be strong. The only case when an IBOutlet should be weak is to avoid a retain cycle. A strong reference cycle can result in memory leaks and app crashes.

Why are outlets weak IOS?

Outlets that you create will therefore typically be weak by default, because: Outlets that you create to, for example, subviews of a view controller's view or a window controller's window, are arbitrary references between objects that do not imply ownership.

What is @IBOutlet weak VAR?

@IBOutlet private weak var someLabel: UILabel! Let's break this down by keyword: @IBOutlet makes Interface Builder recognize the outlet. private ensures the outlet isn't accessed outside the current class. weak is used because in most situations the owner of the outlet isn't the same as the owner of the view.

What does IBOutlet mean?

IBAction and IBOutlet are interface Builder Constants IBOutlet:A Controller class can refer to the object in the nib file using a special constant called IBOutlet. IBActions:Interface objects in the nib file can be set to trigger specific methods in controller class using IBAction as return type of the method.


1 Answers

In only ARC we have to use weak property and in without ARC we have to use unsafe_unretained it is same means for ARC we have to use

@property (weak) IBOutlet WebView *webView;

and for without ARC

@property(unsafe_unretained) IBoulet WebView *webView; 
like image 102
PeterParker Avatar answered Sep 18 '22 06:09

PeterParker