0

I have changed the name of my existing class in my iOS framework. But I want previous code to work properly after developers update the framework, just for one version.

Let say that I was having "ClassA" in the framework, and changed it to "ClassB"

I can do it by using @compatibility_alias directive like this:

@compatibility_alias ClassA ClassB;

However, in this case, developers won't be aware of the internal change. And I want them to really rename ClassA to ClassB in their code, because I want to remove @compatibility_alias directive in future versions.

Is there anyway to warn developer with __deprecated directive? I need some kind of warning mechanism because I want to remove @compatibility_alias directive in future versions.

I tried sth like this:

@compatibility_alias ClassA ClassB; __deprecated

But it did not show any warning on the line where I called ClassA.

Regards,

manuyavuz
  • 176
  • 1
  • 11
  • How about a `#warning` directive, or is that too noisy? – trojanfoe Nov 21 '13 at 14:01
  • Is there a way to show a warning on the line which ClassA is called using `#warning` ? I am not aware of such method. – manuyavuz Nov 21 '13 at 14:14
  • No, it would be in the form of a constant warning that would never go away. I don't think it would work. One thing to consider is actually renaming the class and the user would be forced to do the work immediately (though not much work). As long as you document this, I don't think that would be the end of the world (and you could forget about this issue altogether). – trojanfoe Nov 21 '13 at 14:16
  • I'm actually trying to achieve the same thing right now. Trying to rename a class but leave it there for a while with a deprecation warning. Ideally, using the old name would call though to the renamed class but show the deprecation warning. – Lukas Spieß Mar 21 '15 at 01:12

1 Answers1

0

On top of your deprecated class add __deprecated.

Check the suggested answers here.

Community
  • 1
  • 1
Nikos M.
  • 13,685
  • 4
  • 47
  • 61
  • The problem is, actually I have no ClassA class anymore, I just refactored the class name to ClassB. So I can't use __deprecated for ClassA. – manuyavuz Nov 21 '13 at 14:11
  • keep the compatibility alias as is and add it on top of classB – Nikos M. Nov 21 '13 at 14:13
  • If I do this, warning will be shown everywhere developer uses ClassB, which is the new class that I want developer to use. So it won't work. – manuyavuz Nov 21 '13 at 14:18
  • Actually you want your devs to use classa (deprecated) but you have removed it. This cannot be done. Simply :-) Deprecation means that there will be some time while devs will be able to use both classes. You have gone to the next step, you just dropped the class that you want to replace. – Nikos M. Nov 21 '13 at 14:21
  • I'm aware that I did dropped the previous class directly :) All I'm wondering is that is there any way to warn user during compile without an error, via utilising or not utilising _deprecated directive. – manuyavuz Nov 21 '13 at 14:25
  • 1
    Moreover, using @compatibility_alias, I actually make devs to use both classes without any problem, because "ClassA" occurrences are directly replaced by "ClassB" by compiler. So the behaviour is actually a deprecation behaviour although I don't use `__deprecated` directive. – manuyavuz Nov 21 '13 at 14:33