Getting “Expected a property attribute before 'strong'” when compiling an ARC file with LLVM-GCC
I have a project that contains some files that are using ARC, and some are not. The ones that are not have the compiler flag that disables ARC. That works fine.
I also want to make sure my library compiles for LLVM-GCC and also LLVM Compiler.
I have a property like this:
@property (strong, nonatomic) NSString *foo;
However, when I compile in LLVM-GCC, I get:
“Expected a property attribute before ‘strong'”
If I change strong to retain, it compiles fine.
Strong also works fine in LLVM Compiler.
What am I missing? Isn’t strong synonymous with retain?
- ObjC ARC contraction (clang crash)
- Why is @autoreleasepool still needed with ARC?
- Frontmost UIView with TapGestureRecognizer not receiving touches
- error 'autorelease' is unavailable: not available in automatic reference counting mode
- When and why would I want to declare a local variable as __weak using ARC?
- Do I set properties to nil in dealloc when using ARC?
3 Solutions Collect From Internet About “Getting “Expected a property attribute before 'strong'” when compiling an ARC file with LLVM-GCC”
You’re using an obsolete compiler and expecting it to support new language features. That simply isn’t going to happen. If you’re using keywords introduced with ARC, you need to be using Clang.
As Kevin indicates, if you’re using ARC at any point in your static library project, it will only be compatible with the LLVM Compiler 3.0 and up.
However, if you want to create a framework that uses manual reference counting, yet is usable within ARC-enabled project and is compatible with older compilers, you might need to set up some compiler defines. We had to do this for the Core Plot framework in order to make the headers for that framework compatible across ARC and non-ARC projects built using a variety of compilers and targets.
To do this, I drew from Ryan Petrich’s ZWRCompatibility, which he describes in his answer here, and assembled the following defines:
#if TARGET_OS_IPHONE && defined(__IPHONE_5_0) && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0) && __clang__ && (__clang_major__ >= 3) #define CPT_SDK_SUPPORTS_WEAK 1 #elif TARGET_OS_MAC && defined(__MAC_10_7) && (MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_7) && __clang__ && (__clang_major__ >= 3) #define CPT_SDK_SUPPORTS_WEAK 1 #else #define CPT_SDK_SUPPORTS_WEAK 0 #endif #if CPT_SDK_SUPPORTS_WEAK #define __cpt_weak __weak #define cpt_weak_property weak #else #if __clang__ && (__clang_major__ >= 3) #define __cpt_weak __unsafe_unretained #else #define __cpt_weak #endif #define cpt_weak_property assign #endif
This lets you refer to non-retained (assigned) instance variables like the following:
__cpt_weak CPTAnnotationHostLayer *annotationHostLayer;
with the matching property definition of
@property (nonatomic, readwrite, cpt_weak_property) __cpt_weak CPTAnnotationHostLayer *annotationHostLayer;
For targets of iOS 5.0 and Lion using the LLVM Compiler 3.0, this makes these properties use the safer
__weak qualifier. For iOS 4.0 and Snow Leopard under LLVM Compiler 3.0, this turns to
__unsafe_unretained. Finally, for any other compiler, the qualifier is blank and the property is set to
retain can be used for properties without much of a problem across all compilers.
You are using wrong complier. LLVM GCC does not supports Strong and other ARC keywords. Please set your complier as LLVM compiler 4.2
- Load image from bundle with IOS
- want to display UIProgressView on UIAlertView
- How to detect loss of internet reachability when wifi source loses connection?
- CoreText crashes when run in multiple threads
- Swift How to get integer from string and convert it into integer
- How do I achieve a clearly rendered rotated UILabel?
- How to adjust super view 's height base on subview's size in XIB?
- Swift 3.0 or Swift 2.3 minimum system version requirement and is it deployed in iOS 7
- iPhone/iPod Touch: application executable contains unsupported architecture(s): armv7s (-19031)
- iOS – how do I create a “utility” class that all my controllers can call
- If statement with dates
- How to pass an Error up the stack trace in Swift
- How to convert CLLocation to string in Xcode
- iPhone view move animation
- Registering an icon for my application's document type