• 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: NSPredicate & Editor questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSPredicate & Editor questions


  • Subject: Re: NSPredicate & Editor questions
  • From: Peter Ammon <email@hidden>
  • Date: Thu, 13 Aug 2009 13:49:44 -0700


On Aug 12, 2009, at 3:20 PM, Dave DeLong wrote:

Thanks for the info! I spent some time at NSCoder Night last night poking around with attempting to convert an NSPredicate into an NSCompoundPredicate using the TODParseKit and the BNF definition of NSPredicate grammar in the docs, then eventually gave up. =) (I figured there had to be an easier way, since this seems like a non- unreasonable thing to want to do)

Luckily, I was just pointed to the setObjectValue: approach on StackOverflow.com and have been trying to get that to work.

I've started building a test app to experiment with this. Here's what I've got:

1. Create a new Document-based Cocoa App.
2. Add an IBOutlet to MyDocument called "predicateEditor"
3. Drop an NSPredicateEditor into MyDocument.xib and connect it to File's Owner's predicateEditor outlet.
4. Add a "[predicateEditor addRow:self];" message in MyDocument's windowControllerDidLoadNib: method
5. In the dataOfType:... method, retrieve predicateEditor's objectValue, use NSKeyedArchiver to archive it, and return that as the data.
6. In the readData:ofType:... method, unarchive the data as an NSPredicate and use predicateEditor's setObjectValue: method to restore it.


If I run this, create a predicate, and save it, then it saves nicely to a file. If I then try to open that file, I can NSLog and see that the predicate is getting unarchived properly, but the predicateEditor doesn't load it. Is there anything I'm supposed to be doing besides setObjectValue:? I haven't modified the predicateEditor at all, other than to make the nesting "Compound".

In document based apps, readData:ofType: is called before the nib is loaded. So in your readData:ofType: method, the outlet to the NSPredicateEditor has not yet been populated, so that setObjectValue: goes to nil.


You can unarchive the predicate and store it in your MyDocument, and then push it to the NSPredicateEditor in windowControllerDidLoadNib:. Alternatively, if you're comfortable with bindings, you you can bind the NSPredicateEditor's object value to your document in IB, and then it will pick up the predicate when it's loaded.

Hope this helps,
-Peter
_______________________________________________

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


References: 
 >NSPredicate & Editor questions (From: Dave DeLong <email@hidden>)
 >Re: NSPredicate & Editor questions (From: Peter Ammon <email@hidden>)
 >Re: NSPredicate & Editor questions (From: Dave DeLong <email@hidden>)

  • Prev by Date: Re: Releasing ivars in -didTurnIntoFault. Should set to nil?
  • Next by Date: Re: File's owner, outlets and methods
  • Previous by thread: Re: NSPredicate & Editor questions
  • Next by thread: NSPushAutoreleasePool & NSPopAutoreleasePool?
  • Index(es):
    • Date
    • Thread