5

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?

Community
  • 1
  • 1
Matt N.
  • 1,239
  • 2
  • 11
  • 26
  • Try using `UNAVAILABLE_ATTRIBUTE` instead. It's defined in Apple's headers somewhere, along with `DEPRECATED_ATTRIBUTE`. – Greg Jun 04 '13 at 08:39
  • Yes, thanks. I tried that too, also with no effect. But my question here is not about how to deprecate methods in general but rather how to make this line of code compile. – Matt N. Jun 04 '13 at 08:40
  • I'm starting to think it's not possible to deprecate methods despite having the attributes. They seem to have no effect. Meh. – Matt N. Jun 04 '13 at 08:42
  • 1
    The code snippet you posted compiles for me, and works as intended. What compiler are you using? – Greg Jun 04 '13 at 08:43
  • @PartiallyFinite Heh! Let me try to find out (it probably says somewhere in XCode). – Matt N. Jun 04 '13 at 08:44
  • 1
    Click on your project in the left pane > Select your target in the left pane of that > Build Settings > Build Options > Compiler for C/Objective-C – Greg Jun 04 '13 at 08:46
  • @PartiallyFinite [Got it](http://stackoverflow.com/questions/14186490/how-to-check-the-llvm-compiler-version-xcode-is-using), thank you! It says GCC 4.2. – Matt N. Jun 04 '13 at 08:47
  • Try changing it to something else. I'm using "Apple LLVM compiler 4.2" (the default option). GCC 4.2 would be pretty outdated, since the latest version is 4.7. – Greg Jun 04 '13 at 08:48
  • @PartiallyFinite It doesn't seem to have "Apple LLVM compiler 4.2" but if I try it with "LLVM compiler 4.2" (after clean all targets) I still get wrong number of arguments. – Matt N. Jun 04 '13 at 08:51
  • Interesting. Which Xcode version are you running? – Greg Jun 04 '13 at 08:53
  • 1
    I really don't know what the problem could be, aside from a potentially outdated version of Xcode and/or compiler. – Greg Jun 04 '13 at 08:54
  • @PartiallyFinite It sounds like a plausible explanation, I'm using XCode 3.2.6. I guess it means I will have to live without the message text. Considering that the compiler doesn't produce any warnings for methods I marked deprecated anyway it makes no difference, I suppose. – Matt N. Jun 04 '13 at 08:56
  • I was hoping that if I could make this compile the compiler would also start giving me warnings for the deprecated methods. Now that you have identified the cause I think I can give up on that. It's good to know the cause though: thank you! – Matt N. Jun 04 '13 at 09:07
  • Xcode 3 is pretty ancient at this point. – ipmcc Jun 09 '13 at 12:11
  • @ipmcc I agree but so is my computer and I disagree with the idea that these companies purposefully make new software that forces you to buy new hardware. – Matt N. Jun 09 '13 at 17:48
  • Gotta say, you're missing out. :) – ipmcc Jun 09 '13 at 19:33

1 Answers1

1

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!