Under ARC, the compiler needs to now exactly the kind of ownership the method returns. The default in this case is that the object is not owned by the caller, but in the actual declaration the object may be owned by the caller ("ns_returns_retained" attribute), conversely, you may have a owning method like newBar that returns a non-retained object ("ns_returns_not_retained" attribute), in the former case you get an under-release in the latter you get an over-release, which is detrimental to ARC.
To make ARC deterministic, the compiler has to assume a lot of things so certain behaviours that were okay before are made illegal in ARC to ensure that the behaviour is consistent.
Remy "Psy" Demarest
Le 25 juil. 2012 à 10:27, Andreas Grosam <email@hidden> a écrit :
>
> Under ARC, this won't compile if there is no visible interface for a method 'bar' for any class:
>
> - (id) foo {
> if ([self.something respondsToSelector:@selector(bar)]) {
> return [self.something bar];
> }
> else {
> return nil;
> }
> }
>
>
> error: no known instance method for selector 'bar'
> return [self.model bar];
> ^~~~~~~~~~~~~~~~
>
>
> This is a valid program - but the compiler refuses it!
>
>
> I *could* workaround this issue for instance by adding a protocol somewhere into the translation unit:
>
> @protocol Prot <NSObject>
> - (id) bar ;
> @end
>
>
> After that, I get no warnings/errors anymore. But why would that make the compiler assume that everything is OK *now*? Makes no sense to me.
>
>
> Andreas
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Objc-language mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden