Re: Scripting Bridge && filteredArrayUsingPredicate
Re: Scripting Bridge && filteredArrayUsingPredicate
- Subject: Re: Scripting Bridge && filteredArrayUsingPredicate
- From: email@hidden
- Date: Thu, 3 Jan 2008 03:14:32 +0100
Thanks for taking the time, has. Sounds like my best option is to
check for empty strings, iterate over the search result if necessary
and manually delete non-matching objects from the SBElementArray.
Constantly sucking in each and every track from iTunes is a speed
penalty I just cannot accept.
On Jan 3, 2008 2:17 AM, has <email@hidden> wrote:
>
> On 2 Jan 2008, at 22:31, email@hidden wrote:
>
> > So it's a Cocoa thing then?? Jesus...
>
> Nope, your code below does something different to mine. (I just used
> Ruby as it's a bit quicker to work in.)
>
> > theArtist = @"Beatles";
> > theAlbum = @"";
> >
> > track_array = (SBElementArray *)[libraryPlaylist searchFor:theArtist
> > only:'kSrR']; //artists
> >
> > // Filter by artist, we get a track in the array
> > predicate = [NSPredicate predicateWithFormat:@"artist like[cd] %@",
> > theArtist];
> > track_array = (SBElementArray *)[track_array
> > filteredArrayUsingPredicate:predicate];
> >
> > nameArray = [track_array arrayByApplyingSelector:@selector(name)];
> > NSLog(@"%@", nameArray); // => ("I Feel Fine")
> >
> > // Filter again by album, no go...
> > predicate = [NSPredicate predicateWithFormat:@"album like[cd] %@",
> > theAlbum];
> > track_array = (SBElementArray *)[track_array
> > filteredArrayUsingPredicate:predicate];
> >
> > nameArray = [track_array arrayByApplyingSelector:@selector(name)];
> > NSLog(@"%@", nameArray); // => () Nothing here!!
>
>
> You're applying the second filter to the SBElementArray object
> returned by the first filter, which in turn is operating on the
> SBElementArray returned by the -searchFor: command. That sort of thing
> might be perfectly logical and work just fine in the Cocoa world - but
> remember what I said about Scripting Bridge just being a thin faux-OO
> facade over the real Apple event IPC mechanism. You shouldn't assume
> that just because it's dressed up to look like familiar Cocoa APIs it
> will actually behave like them.
>
> To be honest, I couldn't tell you exactly what the above code is
> actually doing, short of turning on AEDebug and deducing SB's actions
> based on the events it's sending. This sort of intentional obfuscation
> drove me batty in AppleScript; I can't see it being any more popular
> amongst Cocoa users.
>
> ...
>
> Anyway, if you want to apply two conditional tests to a multi-item
> reference, they should be combined into a single logical AND test
> first, for example [1]:
>
>
> artistName = @"Ella Fitzgerald";
> albumName = @"";
>
> itunes = [[ITApplication alloc] initWithBundleID: @"com.apple.itunes"];
>
> test = [
> [[ITIts artist] equals: artistName]
> AND:
> [[ITIts album] equals: albumName]
> ];
>
> ref = [[[[[itunes playlists] at: 1] tracks] byTest: test] name];
>
> trackNames = [[ref get] send];
>
>
> HTH
>
> has
>
> [1] Note: requires revision 418 or later due to a bug I just
> discovered in the -AND: method. Caveat alphaware, as I may have
> mentioned already. :p
> --
>
> 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