Re: How to convert String.Index to UInt?
Re: How to convert String.Index to UInt?
- Subject: Re: How to convert String.Index to UInt?
- From: Quincey Morris <email@hidden>
- Date: Tue, 19 Aug 2014 10:07:00 -0700
On Aug 19, 2014, at 02:06 , Gerriet M. Denkmann <email@hidden> wrote:
> But what about:
> SELPlus aSelector = BetterSelectorFromString ( aSelectorName, "returns object which does NOT need to be released" );
> id a = [ self performSelector: aSelector ];
>
> Or (if modifying SEL is not viable):
> id a = [ self performSelector: aSelector withInfo: "returns object which does NOT need to be released" ]
>
> This should work (as long as I do not lie about my selector), shouldn't it?
In general, the compiler is going to want the equivalent of a method signature — that is, full information about all of the parameters as well as the return value. (Obj-C has already gone down this road. There’s a NSMessageSignature class, not to mention NSInvocation, which has its own memory management rules. These are horrible to use.)
In Obj-C, the whole performSelector thing is unpleasant in general (think of those didEnd… selector parameters), but easy enough in the simplest cases — at the cost of lacking full ARC-correctness.
Obj-C has a solution: blocks. These are superior to performSelector in all functional respects**, but they’re uglier and fussier to write.
Swift has the same solution — closures — and goes to some trouble to make them less ugly and less fussy than the Obj-C version.
I’d say it’s worth putting some effort into retraining yourself to stop using selector-based implementations *in Obj-C*. It’ll improve your Obj-C code, as well as easing any transition to Swift.
** Except perhaps the ease with which they cause retain cycles.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden