• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Scripting Bridge && filteredArrayUsingPredicate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scripting Bridge && filteredArrayUsingPredicate


  • Subject: Re: Scripting Bridge && filteredArrayUsingPredicate
  • From: has <email@hidden>
  • Date: Fri, 28 Dec 2007 18:35:50 +0000

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


  • Follow-Ups:
    • Re: Scripting Bridge && filteredArrayUsingPredicate
      • From: email@hidden
  • Prev by Date: Re: Need Help with Bindings and Core Data...
  • Next by Date: Building a dynamic class factory ( +load init order)
  • Previous by thread: Re: Scripting Bridge && filteredArrayUsingPredicate
  • Next by thread: Re: Scripting Bridge && filteredArrayUsingPredicate
  • Index(es):
    • Date
    • Thread