Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong number of arguments for attribute

Tags:

objective-c

In Objective C there is the following code that marks methods as obsolete:

__attribute__((unavailable("message text")));

This code has been suggested here, here and here, possibly in a few more places that I can't recall off the top of my head right now.

I can't compile this code. The compiler error I get is "Wrong number of arguments specified for the 'unavailable' attribute". Same error for the deprecated attribute. If I remove the string it compiles but I'd like to know how to compile it with the string. Since it has been suggested by several people independently and has even been upvoted it must be working code. But I can't seem to make it compile.

What am I doing wrong? How to make this compile?

like image 337
Matt N. Avatar asked Nov 12 '22 04:11

Matt N.


1 Answers

In my search, I found the clang documentation on this; Clang Language Extensions

My Xcode version is 4.6.2, I tried LLVM-gcc without ARC to ensure that the gcc compiler still worked with the extensions.

My compiler for C/C++/Objective-C options are ; LLVM GCC 4.2 and Apple LLVM compiler.

Both these attributes are in the .h header file. Both LLVM GCC and APPLE LLVM take these two styles

-(void)oldMethod __attribute((deprecated()));
//or
-(void)oldMethod2 DEPRECATED_ATTRIBUTE;

LLVM GCC complained about the following method format, where as Apple LLVM worked properly (This answers your question actually. your compiler is using LLVM GCC or something older)

-(void)oldMethod __attribute((deprecated("Don't use Old Method")));

Long story short, be sure to keep a backup before you go messing with these build settings and changes.

  1. Check that the proper Xcode is running (4.6.2 is latest), I ended up with a clutter of different version and had to do clean up.

  2. Check which compiler versions are available in the project settings under "Build Options". (I indicated that answer above)

  3. For older projects, you may want to check on refactoring with ARC and Convert to modern objective-c. Just be sure to keep a backup, on larger projects it can be a hassle. (Edit->Refactor->Modern Objective-C) Videos; WWDC 2011 Refactoring with Automatic Reference Counting WWDC 2012 Modern Objective-C Videos https://developer.apple.com/videos/wwdc/2012/

    Note: Modern Objective-C refactoring will change to the Apple-LLVM compiler. Along with other changes.

If this answer gets at the core of your question, help me out by up-voting! TIA!

like image 173
Bill Thompson Avatar answered Nov 15 '22 06:11

Bill Thompson