Re: Scripting Bridge && filteredArrayUsingPredicate
Re: Scripting Bridge && filteredArrayUsingPredicate
- Subject: Re: Scripting Bridge && filteredArrayUsingPredicate
- From: email@hidden
- Date: Sat, 29 Dec 2007 17:28:44 +0100
On a similar note, I recently stumbled upon what appears to be another
major flaw in filteredArrayUsingPredicate:. If the predicate is set to
match an empty string "" (a common enough operation when dealing with
meta tags, for example in iTunes), filteredArrayUsingPredicate: always
returns an empty array, regardless if the objects in the unfiltered
array matches the predicate or not.
I use array filtering all over the place, so unless I'm overlooking
something really simple, this means I have to manually check the
passed in criteria on every single occasion, and deal with empty
strings manually, building new SBElementArrays from scratch (as you
cannot remove an object from an SBElementArray, although it is
declared as a subclass of NSMutableArray). Sigh...
This leads me to another question: how do I create a new
SBElementArray? I tried adding SBObjects (iTunesTracks) directly from
the SBElementArray to a NSMutableArray, but the class of this new
array is everything but a SBElementArray. I got NSMutableIndexSets,
SBRelativeHumHumSomething and all sorts of weird things, depending on
the construction. I also tried initializing new SBObjects with the
data/properties from the original SBObjects, but that failed miserably
as well.
F.
On Dec 28, 2007 7:35 PM, has <email@hidden> wrote:
> led248 wrote:
>
> > Thank you, HAS! You are absolutely correct. Apple's sample code does
> > work IF I change the NSPredicate so that it finds at least one match.
> > [...]
> > It never would have crossed
> > my mind that zero matches would result in an error!
>
> It's not obvious, and the behaviour you get varies depending on the
> form of query used. e.g.:
>
> get every disk whose name starts with "M" --> {}
> get name of every application file of desktop --> {}
> get name of (every file whose name starts with "Z") of desktop -->
> error -1728
>
> Most likely it's a design oversight rather than a deliberate feature.
> Alas, this sort of thing is pretty much par for the course in the
> AppleScript world, and something you just have to deal with if you're
> to get things done.
>
>
> > And the sample
> > code will almost certainly error out -- unless you happen to have a
> > mounted disk whose name starts with 'M". You gotta be kidding.
>
> Nope, it wasn't a very well thought-out example. (Although it mightn't
> have been quite so bad if SB didn't turn every little application
> error into an OMFG!!!!1!1!! ObjC exception.)
>
>
> > Now that I know that the code (kinda) works, and I will have to tack
> > on error check gobbledygook, I still don't know what that compiler
> > warning is about:
> >
> > SBElementArray *desiredDisks = [[finder disks]
> > filteredArrayUsingPredicate:startsWithM];
> > warning: initialization from distinct Objective-C type
>
> The compiler warning (gotta love that old-timey gcc crypticness) is
> apparently due to the -filteredArrayUsingPredicate: method returning
> an SBElementArray* when its result is declared as NSArray*. Not very
> clever. To eliminate the warning, type the variable as id or cast the
> method's result to the right type (SBElementArray*) before assigning
> it. Or just use objc-appscript (caveat its current alpha status),
> which doesn't tie itself in such knots in the first place.
>
>
> HTH
>
> has
> --
> http://appscript.sourceforge.net
> http://rb-appscript.rubyforge.org
>
> _______________________________________________
>
> 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
>
_______________________________________________
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