NSXMLElement and namespaces

2010-04-03 Thread Nathan Day
Can anybody help me understand how namespaces works with NSXMLNode etc. There 
is the method

+ [NSXMLNode elementWithName:(NSString *)name URI:(NSString *)URI]


 Which takes an namespace URI, but doesn't seem to use it. I have seems an 
example from google where they pass the namespace URI and then use a name which 
uses the namespace prefix as part of the name, for exmaple

[NSXMLNode elementWithName:@xsl:value-of 
URI:@http://www.w3.org/1999/XSL/Transform;];

If you have to add the prefix to the name then what is the point of the URI 
argument.

Nathan Day
http://homepage.mac.com/nathan_day/

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Terminating subtasks reliably

2010-04-03 Thread Dave Keck
 Call getppid, set up the kevent listener, then before you actually
 block in kevent, call getppid *again*. If the answer matches the first
 call, then you can go ahead and call kevent. If the answer doesn't
 match, you've hit the race condition you outline here, your parent is
 dead, and you can exit immediately. If the parent quits after the
 second getppid but before the call to kevent, you should still get the
 exit notification because you registered it before the parent quit.

Ah - that should do it.

I was skeptical though, so I took a peek at the kernel's
exiting-process code
(http://www.opensource.apple.com/source/xnu/xnu-1504.3.12/bsd/kern/kern_exit.c);
indeed it looks like this technique is free from races, due to
proc_exit() both issuing the NOTE_EXIT event and putting the exiting
process in a reapable state _after_ all children of the exiting
process have been reparented by launchd.

For the archives: http://pastie.org/901581
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: iPhone CoreData TableView not updating (solved)

2010-04-03 Thread Arnold Nefkens
I found it:

The .h was @interface AdresViewController : UITableViewController. 
I changed this to @interface AdresViewController : UIViewController and it now 
does work... 

;-)
On 3 apr 2010, at 06:08, Arnold Nefkens wrote:

 Hello List, 
 
 I'm a newbie on iPhone Programming, so please bear with me.
 
 I did the first 7 chapters of More iPhone 3 Development, tackling iPhone 
 SDK3 from Apress regarding the use of CoreData. In these 7 chapters a lot is 
 explained and finally a series of classes and categories are being build that 
 one can use as a Generic Controller for editing data stored in CoreData.
 
 So I bult a new application where I inserted these classes, and created a new 
 viewController for my specific needs. Almost everything works, except that 
 the tableView is not updated when I create a new item for in the DB, The item 
 is however created, but only visible if I quit the App and start it again. 
 Apparently something is not right.
 
 I double checked the 4 NSFetechedResult delegates, but it just does not work. 
 I tried to insert [self.tableView reloadData] on a number of places, but to 
 no avail.
 
 Can someone of you check my ViewController code? And point me in the right 
 direction where I'm missing the ball?
 
 I'll send you the code off-list
 
 Your help and effort is much appreciated.
 
 Kind regards, 
 
 Arnold Nefkens
 
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 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:
 http://lists.apple.com/mailman/options/cocoa-dev/lists%40nefkens-ict.nl
 
 This email sent to li...@nefkens-ict.nl

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


CGPoint and KVO

2010-04-03 Thread Roland King
I have a property which is a CGPoint and I'm observing it. I didn't really know 
what to expect in the change dictionary (I have NSKeyValueObservingOld as the 
observation flags) so I stuck in a breakpoint and went looking. After messing 
about in the debugger when the property was changed I found the old value was 
an NSConcreteValue and the following code appears to work to extract the 
CGPoint from it

CGPoint oldPoint; 
id oldValue = [ change valueForKey:NSKeyValueChangeOld ]; 
[ (NSValue*)oldValue getValue:oldPoint ]

Is this correct? I've failed to find anything much in the KVO documentation 
about CGPoint or how I should expect to receive structs or other primitives.

This is iPhone OS (incase that makes a difference). 
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: CGPoint and KVO

2010-04-03 Thread Kiel Gillard
On 04/04/2010, at 1:40 AM, Roland King wrote:

 I have a property which is a CGPoint and I'm observing it. I didn't really 
 know what to expect in the change dictionary (I have NSKeyValueObservingOld 
 as the observation flags) so I stuck in a breakpoint and went looking. After 
 messing about in the debugger when the property was changed I found the old 
 value was an NSConcreteValue and the following code appears to work to 
 extract the CGPoint from it
 
   CGPoint oldPoint; 
   id oldValue = [ change valueForKey:NSKeyValueChangeOld ]; 
   [ (NSValue*)oldValue getValue:oldPoint ]
 
 Is this correct? I've failed to find anything much in the KVO documentation 
 about CGPoint or how I should expect to receive structs or other primitives.

In the case of NSPoint/CGPoint:

CGPoint oldPoint = [oldValue pointValue];

 This is iPhone OS (incase that makes a difference). 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 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:
 http://lists.apple.com/mailman/options/cocoa-dev/kiel.gillard%40gmail.com
 
 This email sent to kiel.gill...@gmail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: CGPoint and KVO

2010-04-03 Thread Roland King
Thanks

pointValue didn't work on iPhone OS but CGPointValue did, luckily, as that's 
the one I needed. That seems to be a UIKit extension. I've switched to that. 

was my original method (apart from being clunky) wrong? It did work. 


On 03-Apr-2010, at 10:43 PM, Kiel Gillard wrote:

 On 04/04/2010, at 1:40 AM, Roland King wrote:
 
 I have a property which is a CGPoint and I'm observing it. I didn't really 
 know what to expect in the change dictionary (I have NSKeyValueObservingOld 
 as the observation flags) so I stuck in a breakpoint and went looking. After 
 messing about in the debugger when the property was changed I found the old 
 value was an NSConcreteValue and the following code appears to work to 
 extract the CGPoint from it
 
  CGPoint oldPoint; 
  id oldValue = [ change valueForKey:NSKeyValueChangeOld ]; 
  [ (NSValue*)oldValue getValue:oldPoint ]
 
 Is this correct? I've failed to find anything much in the KVO documentation 
 about CGPoint or how I should expect to receive structs or other primitives.
 
 In the case of NSPoint/CGPoint:
 
 CGPoint oldPoint = [oldValue pointValue];
 
 This is iPhone OS (incase that makes a difference). 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 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:
 http://lists.apple.com/mailman/options/cocoa-dev/kiel.gillard%40gmail.com
 
 This email sent to kiel.gill...@gmail.com
 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: CGPoint and KVO

2010-04-03 Thread Clark S. Cox III
The main issue with the original code is that it assumes that the value is a 
CGPoint. If it were anything smaller, you'd get garbage values in your point, 
and if it were any larger, you'd be stomping on memory as you ran off the end 
of your CGPoint variable.

Any time you use -[NSValue getValue:], you should check to make sure that the 
NSValue represents the correct type.

Sent from my iPad

On Apr 3, 2010, at 7:52, Roland King r...@rols.org wrote:

 Thanks
 
 pointValue didn't work on iPhone OS but CGPointValue did, luckily, as that's 
 the one I needed. That seems to be a UIKit extension. I've switched to that. 
 
 was my original method (apart from being clunky) wrong? It did work. 
 
 
 On 03-Apr-2010, at 10:43 PM, Kiel Gillard wrote:
 
 On 04/04/2010, at 1:40 AM, Roland King wrote:
 
 I have a property which is a CGPoint and I'm observing it. I didn't really 
 know what to expect in the change dictionary (I have NSKeyValueObservingOld 
 as the observation flags) so I stuck in a breakpoint and went looking. 
 After messing about in the debugger when the property was changed I found 
 the old value was an NSConcreteValue and the following code appears to work 
 to extract the CGPoint from it
 
 CGPoint oldPoint; 
 id oldValue = [ change valueForKey:NSKeyValueChangeOld ]; 
 [ (NSValue*)oldValue getValue:oldPoint ]
 
 Is this correct? I've failed to find anything much in the KVO documentation 
 about CGPoint or how I should expect to receive structs or other primitives.
 
 In the case of NSPoint/CGPoint:
 
 CGPoint oldPoint = [oldValue pointValue];
 
 This is iPhone OS (incase that makes a difference). 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 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:
 http://lists.apple.com/mailman/options/cocoa-dev/kiel.gillard%40gmail.com
 
 This email sent to kiel.gill...@gmail.com
 
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 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:
 http://lists.apple.com/mailman/options/cocoa-dev/clarkcox3%40gmail.com
 
 This email sent to clarkc...@gmail.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


re: iPhone CoreData TableView not updating

2010-04-03 Thread Ben Trumbull
 I did the first 7 chapters of More iPhone 3 Development, tackling iPhone 
 SDK3 from Apress regarding the use of CoreData. In these 7 chapters a lot is 
 explained and finally a series of classes and categories are being build that 
 one can use as a Generic Controller for editing data stored in CoreData.
 
 So I bult a new application where I inserted these classes, and created a new 
 viewController for my specific needs. Almost everything works, except that 
 the tableView is not updated when I create a new item for in the DB, The item 
 is however created, but only visible if I quit the App and start it again. 
 Apparently something is not right.
 
 I double checked the 4 NSFetechedResult delegates, but it just does not work. 
 I tried to insert [self.tableView reloadData] on a number of places, but to 
 no avail.

Have you tried starting a new project from the template ?  That produces a 
completely functional Core Data application you can experiment with.  I'm not 
familiar with the book, it's possible there's a bug in their sample code.

If you're having problems with the NSFetchedResultsController, please note that 
the cache is *persistent* across application runs.  The NSFetchRequest is a 
read only property.  You should not mutate it.  If you change the 
NSFetchRequest, NSPredicate (or the varargs), or NSSortDescriptor in any way, 
the cache will be invalid.  In 3.1, this kinda usually worked anyway.  In 3.2 
and later, the caching is more aggressive and produces much faster launch times 
for FRC with complex string queries.  This also means that buggy code that got 
away with it on 3.1 will no longer if it's recompiled against the 3.2 SDK (3.1 
binaries still run fine)

You may find the behavior more intuitive if you opt out with a nil cache name.

- Ben

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


re: Invalidated managed objects

2010-04-03 Thread Ben Trumbull
 When I create a document, save it, then save as, then save as again, it 
 duplicates the persistent store, so the managed objects I have been using in 
 my application are all invalidated. 
 
 Now there are a whole lot of places in my application where I have KVO set up 
 on properties of the managed objects, and some places where I have the 
 managed objects set as instance variables of my objects. I was not expecting 
 them to be invalidated by the save as operation. 

They are not invalidated as part of Save.  They are as part of Save As since 
that creates a new document, with a new persistent store, a new coordinator, 
new pretty much everything.  Save As is creating a duplicate, so the original 
content still exists.  However, the UI needs to be bound to the new content.  
Think of the behavior of TextEdit.  Save As is like close old, duplicate, open 
new

 And created a method to refresh my data:
 
 
 - (void)managedObjectsChanged:(NSNotification *)notification {
   if ([[notification userInfo] objectForKey:NSInvalidatedObjectsKey]) {
   NSSet *objects = [[notification userInfo] 
 objectForKey:NSInvalidatedObjectsKey];
   for (NSManagedObject *obj in objects) {
   [[self managedObjectContext] refreshObject:obj 
 mergeChanges:YES];
   }
   } else if ([[notification userInfo] 
 objectForKey:NSInvalidatedAllObjectsKey]) {
   for (NSManagedObject *obj in [[self managedObjectContext] 
 registeredObjects]) {
   [[self managedObjectContext] refreshObject:obj 
 mergeChanges:YES];
   }
   }
 }
 
 I have confirmed that this is called in the save/save as/save as scenario, 
 with the NSInvalidatedAllObjectsKey, and my object is getting sent the 
 refreshObject message...But when I go to access my data, it still tells me 
 that it has been invalidated. Am I doing something wrong here?

Yes.  You cannot resurrect invalidated objects.  They are toast.  That's why 
you're getting an exception.  Nor would you want to in this case as they all 
represent content from the old (closed) document not the new saved as document. 
 You need to toss all these references and then go through the regular I just 
opened a new document code path for your newly saved document to reconstruct 
the KVO observations.

The canonical solution is to tell your controller objects like 
NSArrayController to refetch from the new document.   It sounds like you're 
fighting the document based Save As behavior.  It's close the existing 
document, save the current state to a new document, open new document

- Ben

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSPredicate/NSExpression - can they solve this Core Data problem?

2010-04-03 Thread Ben Trumbull
They are noted in the NSExpression.h header with API to create them and a 
comment to their functionality.

- Ben

 Is the use of SUBQUERY() documented anywhere?  The only mention I've seen of 
 it is in the reserved keywords section of the Predicate Format String Syntax 
 guide.
 
 Dave
 
 On Apr 2, 2010, at 3:42 PM, Ben Trumbull wrote:
 
  NSComparisonPredicate* exprPred = (NSComparisonPredicate*)[NSPredicate 
 predicateWithFormat:@SUBQUERY(self, $key, %...@.$key != nil) == 0, obj];
  NSExpression* expr = [exprPred leftExpression];
  NSLog(@expression subquery results = %@, [expr 
 expressionValueWithObject:keys context:nil]);

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


What is the runtime context of an event tap?

2010-04-03 Thread Pat Wilson
When an event tap is created using CGEventTapCreate, which 
process, or thread actually runs the callback function? The one 
which created the tap, the first responder, ...?



Thanks in advance,
Pat.
--
Pat Wilson
mailto:p...@ieee.org

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


How do I get a file reference w/o relying on the path?

2010-04-03 Thread Brad Stone
I want to store a reference to a file in an ivar that will allow the user to 
change the file's name and/or the directory (i.e. the path) and still allow me 
to access it.  I don't want to create a file (like an ailas).  I need to store 
the file reference in a variable so I can open the file no matter where the 
user moves it or renames it.

For those of you who know REALbasic I can do this easily with 
FolderItem.GetSaveInfo. 

How can I do this in Cocoa?

Thanks___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Invalidated managed objects

2010-04-03 Thread Quincey Morris
On Apr 3, 2010, at 12:05, Ben Trumbull wrote:

 The canonical solution is to tell your controller objects like 
 NSArrayController to refetch from the new document.   It sounds like you're 
 fighting the document based Save As behavior.  It's close the existing 
 document, save the current state to a new document, open new document

Do you mean fighting the NSPersistentDocument Save As behavior?

My understanding is that close the existing document, save the current state 
to a new document, open new document is *not* the semantics of plain 
NSDocument Save As -- the whole point being that transient state is preserved 
across a Save As. No NSDocument-based (non-NSPersistentDocument-based) 
application is required to discard all of its in-memory object references after 
doing a Save As, as far as I'm aware.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: What is the runtime context of an event tap?

2010-04-03 Thread Ken Thomases
On Apr 3, 2010, at 5:16 PM, Pat Wilson wrote:

 When an event tap is created using CGEventTapCreate, which process, or thread 
 actually runs the callback function? The one which created the tap, the first 
 responder, ...?

The first responder isn't a thread, process, or runtime/execution context.  
That aspect of your question doesn't make any sense, just so you know.

The documentation for CGEventTapCreate says:

 Your callback function is invoked from the run loop to which the event tap is 
 added as a source. The thread safety of the callback is defined by the run 
 loop’s environment.

Since a run loop is directly associated to a thread, you control which thread 
the callback is called on.  If you add the run loop source for the returned 
Core Foundation mach port to the current run loop, then the callback will be 
called on the current thread.  If you add it to the main run loop, then it will 
be called on the main thread.  Etc.

Regards,
Ken

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How do I get a file reference w/o relying on the path?

2010-04-03 Thread Ken Thomases
On Apr 3, 2010, at 5:20 PM, Brad Stone wrote:

 I want to store a reference to a file in an ivar that will allow the user to 
 change the file's name and/or the directory (i.e. the path) and still allow 
 me to access it.  I don't want to create a file (like an ailas).  I need to 
 store the file reference in a variable so I can open the file no matter where 
 the user moves it or renames it.

FSRefs have the property you desire.  As of Snow Leopard, though, the new 
recommended technique is to use a file reference NSURL.  Check the NSURL 
documentation and also:

http://developer.apple.com/mac/library/documentation/cocoa/conceptual/LowLevelFileMgmt/Articles/FileManagementNSURL.html


Note that an alias _record_ is different from an alias _file_.  An alias record 
is data in memory and is suitable for this purpose, but perhaps overkill.

As of Snow Leopard, alias records are deprecated in favor of bookmark data, 
but, again, it's probably overkill.  (Both alias records and bookmark data are 
more suitable if the reference is to be persisted for use by a later process.  
Also, both can apply more robust searching heuristics to find an appropriate 
file even if it isn't the original.  For example, if the original is deleted 
and replaced with a new file of the same name.)

Cheers,
Ken

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Two text fields, one outlet?

2010-04-03 Thread Jenny M
Is it possible to link multiple NSTextFields to one outlet? I have
three views - one of A items, one of B items, and one of both A and B
items. So the text boxes in the A view also exists in the AB view,
and the value needs to be able to appear in both, though not at the
same time. I have a method that calculates values and sets the textbox
values (or label values, same concept) using an outlet, but I don't
want it to set 2 outlets, I want it to just set 1.

Is this possible using outlets or bindings??

Or is there a way I can place two NSViews into one NSView so there's
only one copy of everything?

Thanks...
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How do I get a file reference w/o relying on the path?

2010-04-03 Thread Brad Stone
Very interesting.  According to the documentation if I want to store the 
reference and want it to persist after a reboot I need to do a bookmark.  

You should not store or archive file reference URLs. A file’s ID may be 
different for different boots of the operating system. If you need to store a 
URL, see “Working with Bookmarks and Aliases.”
THANK YOU so much for pointing me in the correct direction.


On Apr 3, 2010, at 6:55 PM, Ken Thomases wrote:

 On Apr 3, 2010, at 5:20 PM, Brad Stone wrote:
 
 I want to store a reference to a file in an ivar that will allow the user to 
 change the file's name and/or the directory (i.e. the path) and still allow 
 me to access it.  I don't want to create a file (like an ailas).  I need to 
 store the file reference in a variable so I can open the file no matter 
 where the user moves it or renames it.
 
 FSRefs have the property you desire.  As of Snow Leopard, though, the new 
 recommended technique is to use a file reference NSURL.  Check the NSURL 
 documentation and also:
 
 http://developer.apple.com/mac/library/documentation/cocoa/conceptual/LowLevelFileMgmt/Articles/FileManagementNSURL.html
 
 
 Note that an alias _record_ is different from an alias _file_.  An alias 
 record is data in memory and is suitable for this purpose, but perhaps 
 overkill.
 
 As of Snow Leopard, alias records are deprecated in favor of bookmark data, 
 but, again, it's probably overkill.  (Both alias records and bookmark data 
 are more suitable if the reference is to be persisted for use by a later 
 process.  Also, both can apply more robust searching heuristics to find an 
 appropriate file even if it isn't the original.  For example, if the original 
 is deleted and replaced with a new file of the same name.)
 
 Cheers,
 Ken
 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Invalidated managed objects

2010-04-03 Thread Gideon King
Wow, this is huge! Obviously the user doesn't expect the document to disappear 
and a new one open up just because they did a Save As operation, so I would 
have to go through every single part of the application, work out every 
reference to a managed object, and either throw them away or fetch new ones, 
and also lose the undo stack, and I'm not sure how I would keep my current 
selections in the array controllers and recreate all my other non-persistent 
state so that the user doesn't lose what they're doing. 

On 04/04/2010, at 5:05 AM, Ben Trumbull wrote:

 They are not invalidated as part of Save.  They are as part of Save As since 
 that creates a new document, with a new persistent store, a new coordinator, 
 new pretty much everything.  Save As is creating a duplicate, so the original 
 content still exists.  However, the UI needs to be bound to the new content.  
 Think of the behavior of TextEdit.  Save As is like close old, duplicate, 
 open new

If I was doing this just with ordinary objects, doing a Save As would not 
affect the objects I am working with at all. Taking the example of TextEdit, it 
does not lose my selection, reload my window, or lose my undo stack when I do a 
Save As. Logically for the user, they are still working on the same document - 
it just happens to be stored in a different location. If we're thinking of a 
layered application architecture, the physical location of the file shouldn't 
affect the objects at a higher layer, IMHO - but that's just philosophical 
discussion - I need to get to a solution for this problem.

 
 Yes.  You cannot resurrect invalidated objects.  They are toast.  That's why 
 you're getting an exception.  Nor would you want to in this case as they all 
 represent content from the old (closed) document not the new saved as 
 document.  You need to toss all these references and then go through the 
 regular I just opened a new document code path for your newly saved 
 document to reconstruct the KVO observations.
 

This might be manageable to fix (but very time consuming) for instance 
variables, but I also have various arrays, dictionaries, array controllers etc 
etc that hold references to my managed objects too. I guess I really don't get 
the design pattern for this. Trying to keep the UI layer as separate as 
possible from the model, I have lots of KVO to keep the UI up to date with the 
changes to the data. I was not expecting to have to break  those KVO 
connections and have to re-establish them with new objects, and am not sure 
what the impact of this will be, since some of them use the initial option to 
set up state in the non-persistent side of things. In one class, I have over 
100 of these, and many other classes have quite a few that will have to be 
dealt with too.

I'm going to have to take a good long hard look at this to see whether this is 
possible to do with a reasonable amount of effort in my application, or whether 
to ditch core data. I probably have literally hundreds of places in my 
application where it has references to managed objects. I had no idea this was 
a bad thing, and I don't recall it being mentioned anywhere in the 
documentation. In fact the NSPersistentDocument core data tutorial has a 
reference to the managed object stored in the document. I haven't actually 
built that entire project to see whether it would have Save As problems on the 
second save as or load and save as, but I guess it would.

Is there some documentation somewhere on how this is supposed to be done in the 
architecture? 

Is there a working example somewhere based on NSPersistentDocument and 
NSAtomicStore?

For me to get this far into my application development and find out that 
managed objects are really transient in this sense, and that I must not hold 
any reference to them, or if I do, make sure I can handle the need to re-fetch 
them in their entirety as completely new objects, and maintain the current 
state as far as the user is concerned...well I think I must be massively on the 
wrong track as far as how you should be using core data objects is concerned, 
and would really like to see some complete working examples of how to do this 
properly. 

 The canonical solution is to tell your controller objects like 
 NSArrayController to refetch from the new document.   It sounds like you're 
 fighting the document based Save As behavior.  It's close the existing 
 document, save the current state to a new document, open new document
 
 - Ben
 

I have just checked, and 26 of my nib files have array controllers in them, but 
I'm not sure how they are all referenced, in order to force them to reload, or 
how to get them to keep their selection so there is no change for the user.

I don't feel that I can adequately deal with this until I understand the 
intended design pattern for an application based on NSPersistentDocument and 
NSAtomicStore, and see how the necessary updates can happen without affecting 
the user.

TIA


Re: Invalidated managed objects

2010-04-03 Thread Ben Trumbull

On Apr 3, 2010, at 5:07 PM, Gideon King wrote:

 Wow, this is huge! Obviously the user doesn't expect the document to 
 disappear and a new one open up just because they did a Save As operation

I have I'm afraid led you astray.  The invalidated objects are not coming from 
the Save As operation.  The managed objects in the MOC bound to the 
NSPersistentDocument, and any other MOCs bound to that same PSC will keep the 
NSManagedObjects themselves in sync with the underlying document even as it is 
remapped to a new file.  I'll send you a sample project from the template that 
logs the notifications from NSManagedObjectContext and 
NSPersistentStoreCoordinator.  The NSManagedObject pointers remain undisturbed. 

2010-04-03 18:13:41.110 testDocs[14260:a0f] PSC changed:  {
changedUUID = (
NSSQLCore: 0x1025513e0,
NSSQLCore: 0x103051890,
(
0x1025a4bc0 
x-coredata://7401BACF-50F9-4699-8B65-520963A9B084/Entity/p3,
0x103055bc0 
x-coredata://9D960070-9CAE-4BDD-9EDF-99ACCD83AF7F/Entity/p1,
0x102504fb0 
x-coredata://7401BACF-50F9-4699-8B65-520963A9B084/Entity/p2,
0x103051d40 
x-coredata://9D960070-9CAE-4BDD-9EDF-99ACCD83AF7F/Entity/p3,
0x102598810 
x-coredata://7401BACF-50F9-4699-8B65-520963A9B084/Entity/p1,
0x1004eeb10 
x-coredata://9D960070-9CAE-4BDD-9EDF-99ACCD83AF7F/Entity/p2
)
);
}
2010-04-03 18:13:41.112 testDocs[14260:a0f] PSC changed.  Registered objects = 
{(
NSManagedObject: 0x1004db090 (entity: Entity; id: 0x103051d40 
x-coredata://9D960070-9CAE-4BDD-9EDF-99ACCD83AF7F/Entity/p3 ; data: {
name = baz;
}),
NSManagedObject: 0x1004db120 (entity: Entity; id: 0x103055bc0 
x-coredata://9D960070-9CAE-4BDD-9EDF-99ACCD83AF7F/Entity/p1 ; data: {
name = foo;
}),
NSManagedObject: 0x1004daea0 (entity: Entity; id: 0x1004eeb10 
x-coredata://9D960070-9CAE-4BDD-9EDF-99ACCD83AF7F/Entity/p2 ; data: {
name = zap;
})
)}
2010-04-03 18:13:53.604 testDocs[14260:a0f] PSC changed:  {
changedUUID = (
NSSQLCore: 0x103051890,
NSSQLCore: 0x103062860,
(
0x10305b680 
x-coredata://9D960070-9CAE-4BDD-9EDF-99ACCD83AF7F/Entity/p1,
0x10306a890 
x-coredata://381F89A2-9204-45E8-850B-1CED8022E32E/Entity/p1,
0x10305b3c0 
x-coredata://9D960070-9CAE-4BDD-9EDF-99ACCD83AF7F/Entity/p2,
0x10306aa80 
x-coredata://381F89A2-9204-45E8-850B-1CED8022E32E/Entity/p2,
0x1030681e0 
x-coredata://9D960070-9CAE-4BDD-9EDF-99ACCD83AF7F/Entity/p3,
0x10306ae20 
x-coredata://381F89A2-9204-45E8-850B-1CED8022E32E/Entity/p3
)
);
}
2010-04-03 18:13:53.604 testDocs[14260:a0f] PSC changed.  Registered objects = 
{(
NSManagedObject: 0x1004db090 (entity: Entity; id: 0x10306ae20 
x-coredata://381F89A2-9204-45E8-850B-1CED8022E32E/Entity/p3 ; data: {
name = baz;
}),
NSManagedObject: 0x1004db120 (entity: Entity; id: 0x10306a890 
x-coredata://381F89A2-9204-45E8-850B-1CED8022E32E/Entity/p1 ; data: {
name = foo;
}),
NSManagedObject: 0x1004daea0 (entity: Entity; id: 0x10306aa80 
x-coredata://381F89A2-9204-45E8-850B-1CED8022E32E/Entity/p2 ; data: {
name = zap;
})
)}


There are no invalidate managed objects if you create a Core Data document 
based app from the Xcode template and then perform Save As.  I'll take another 
look at your sample project.

- Ben



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Invalidated managed objects

2010-04-03 Thread Gideon King
Phew, that's a relief. I'll look forward to hearing what I'm doing wrong in my 
sample project then.

Regards

Gideon 

On 04/04/2010, at 11:22 AM, Ben Trumbull wrote:

 
 On Apr 3, 2010, at 5:07 PM, Gideon King wrote:
 
 Wow, this is huge! Obviously the user doesn't expect the document to 
 disappear and a new one open up just because they did a Save As operation
 
 I have I'm afraid led you astray.  The invalidated objects are not coming 
 from the Save As operation.  The managed objects in the MOC bound to the 
 NSPersistentDocument, and any other MOCs bound to that same PSC will keep the 
 NSManagedObjects themselves in sync with the underlying document even as it 
 is remapped to a new file.  I'll send you a sample project from the template 
 that logs the notifications from NSManagedObjectContext and 
 NSPersistentStoreCoordinator.  The NSManagedObject pointers remain 
 undisturbed. 
 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How do I get a file reference w/o relying on the path?

2010-04-03 Thread Jens Alfke
Ken, he asked for a reference that wouldn't break if the file were moved or 
renamed. Neither FSrefs nor URLs have that property.

Brad, what you want is a bookmark (in 10.6) or an alias reference. Aliases 
didn't have a Cocoa API until 10.6, but the procedural API isn't hard to use. 

--Jens {via iPad}

On Apr 3, 2010, at 3:55 PM, Ken Thomases k...@codeweavers.com wrote:

 On Apr 3, 2010, at 5:20 PM, Brad Stone wrote:
 
 I want to store a reference to a file in an ivar that will allow the user to 
 change the file's name and/or the directory (i.e. the path) and still allow 
 me to access it.  I don't want to create a file (like an ailas).  I need to 
 store the file reference in a variable so I can open the file no matter 
 where the user moves it or renames it.
 
 FSRefs have the property you desire.  As of Snow Leopard, though, the new 
 recommended technique is to use a file reference NSURL.  Check the NSURL 
 documentation and also:
 
 http://developer.apple.com/mac/library/documentation/cocoa/conceptual/LowLevelFileMgmt/Articles/FileManagementNSURL.html
 
 
 Note that an alias _record_ is different from an alias _file_.  An alias 
 record is data in memory and is suitable for this purpose, but perhaps 
 overkill.
 
 As of Snow Leopard, alias records are deprecated in favor of bookmark data, 
 but, again, it's probably overkill.  (Both alias records and bookmark data 
 are more suitable if the reference is to be persisted for use by a later 
 process.  Also, both can apply more robust searching heuristics to find an 
 appropriate file even if it isn't the original.  For example, if the original 
 is deleted and replaced with a new file of the same name.)
 
 Cheers,
 Ken
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 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:
 http://lists.apple.com/mailman/options/cocoa-dev/jens%40mooseyard.com
 
 This email sent to j...@mooseyard.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Two text fields, one outlet?

2010-04-03 Thread Jens Alfke
No, an outlet is a single variable that can point to only one object at a time. 
(You can't use NSArrays as outlet values.) you'll need multiple outlets, or one 
view you move between two superviews. 

--Jens {via iPad}

On Apr 3, 2010, at 4:22 PM, Jenny M safflo...@gmail.com wrote:

 Is it possible to link multiple NSTextFields to one outlet? I have
 three views - one of A items, one of B items, and one of both A and B
 items. So the text boxes in the A view also exists in the AB view,
 and the value needs to be able to appear in both, though not at the
 same time. I have a method that calculates values and sets the textbox
 values (or label values, same concept) using an outlet, but I don't
 want it to set 2 outlets, I want it to just set 1.
 
 Is this possible using outlets or bindings??
 
 Or is there a way I can place two NSViews into one NSView so there's
 only one copy of everything?
 
 Thanks...
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 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:
 http://lists.apple.com/mailman/options/cocoa-dev/jens%40mooseyard.com
 
 This email sent to j...@mooseyard.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Invalidated managed objects

2010-04-03 Thread Ben Trumbull

On Apr 3, 2010, at 6:25 PM, Gideon King wrote:

 Phew, that's a relief. I'll look forward to hearing what I'm doing wrong in 
 my sample project then.
 
 Regards
 
 Gideon 
 
 On 04/04/2010, at 11:22 AM, Ben Trumbull wrote:
 
 
 On Apr 3, 2010, at 5:07 PM, Gideon King wrote:
 
 Wow, this is huge! Obviously the user doesn't expect the document to 
 disappear and a new one open up just because they did a Save As operation
 
 I have I'm afraid led you astray.  The invalidated objects are not coming 
 from the Save As operation.  The managed objects in the MOC bound to the 
 NSPersistentDocument, and any other MOCs bound to that same PSC will keep 
 the NSManagedObjects themselves in sync with the underlying document even as 
 it is remapped to a new file.  I'll send you a sample project from the 
 template that logs the notifications from NSManagedObjectContext and 
 NSPersistentStoreCoordinator.  The NSManagedObject pointers remain 
 undisturbed. 


Okay.  The invalidations are coming from the PSC when it removes the old store. 
 At this point it's already added the new store, and it's already told the MOC 
to switch all the objectIDs from its MOs to point to the new store.  The 
problem is that your custom store wasn't being honest about the objectIDs, it 
wasn't even saving them at all, so the remapping between the old and new store 
fails.  At that point, the MOC still has objects from the old store in it, 
because the new store handed out random IDs and the mapping failed to find them.

So I changed your save method to write out both the UUID and the string data so 
your store could properly reconstruct the cache node it loads.  

There was another subtle issue from your reusing the metadata dictionary to 
hold your row data.  The problem is you set the metadata at unfortunate times, 
both before and after the store is created.  Instead of changing it in -init 
(too soon) and in -load (too late), it works better to use -loadMetadata.  This 
is a problem for you since you were overwriting the in memory metadata with the 
plist you wrote to disk which effectively caused the store to change it's UUID. 
 The documentation isn't clear on this, so you shouldn't feel bad about missing 
this part.  You also had -metadata spontaneously mutate the row data, which is 
bad.

It's really important for stores to keep their UUID, and for them to hand back 
the same objectID for an object that they did when we asked before.  Otherwise 
constructing a map from old ids to new ids and looking up stores by their UUID 
is kinda hard.

I'll send you back the original and edited sample projects so you can diff them.

- Ben

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Invalidated managed objects

2010-04-03 Thread Gideon King
Excellent, thanks for that. I thought that once a managed object ID had been 
assigned, that newReferenceObjectForManagedObject: should always return the 
same value, so I was regenerating it from the previous data instead of 
generating a new one if it either had a temporary object id or no object id. I 
will switch over my code to do this.

In my current implementation, I have a base class for all my managed objects 
that has an id string (elementID) set in it. The only times it is persisted is 
for objects that I need to refer to in relationships. This means I can 
regenerate the value from the managed objects if necessary, so my new method 
will look like this:

- (id)newReferenceObjectForManagedObject:(NSManagedObject*)managedObject {
NSManagedObjectID *oid = [managedObject objectID];

if ((oid == nil) || [oid isTemporaryID]) {
NSString *aUUID = [NMFoundation generateUUID];
managedObject.elementID = aUUID;
}

return [[NSString alloc] initWithString:managedObject.elementID];
}

It's really helpful to have your input on this - I spent forever looking for 
this, and didn't see it because I didn't fully understand when the reference 
object needed to be the same and when it needed to be different.

There is only one area of my code where this will cause an issue, where I 
pre-generate some of the xml for my file using some references to some managed 
objects. I'm sure I'll be able to find a way around this though.

Hopefully that will resolve that issue.

Also, I had not noticed the loadMetadata: method, so was just creating it in 
the init for new files, or in my load method for existing ones. I will have to 
do a bit of work to change that to load using loadMetadata: since I will have 
to extract the file from a zip file separately from the main load method which 
already unzips to a temporary folder. Not a biggie though.


Hopefully on the home straight now...

Regards

Gideon

 
 Okay.  The invalidations are coming from the PSC when it removes the old 
 store.  At this point it's already added the new store, and it's already told 
 the MOC to switch all the objectIDs from its MOs to point to the new store.  
 The problem is that your custom store wasn't being honest about the 
 objectIDs, it wasn't even saving them at all, so the remapping between the 
 old and new store fails.  At that point, the MOC still has objects from the 
 old store in it, because the new store handed out random IDs and the mapping 
 failed to find them.
 
 So I changed your save method to write out both the UUID and the string data 
 so your store could properly reconstruct the cache node it loads.  
 
 There was another subtle issue from your reusing the metadata dictionary to 
 hold your row data.  The problem is you set the metadata at unfortunate 
 times, both before and after the store is created.  Instead of changing it in 
 -init (too soon) and in -load (too late), it works better to use 
 -loadMetadata.  This is a problem for you since you were overwriting the in 
 memory metadata with the plist you wrote to disk which effectively caused the 
 store to change it's UUID.  The documentation isn't clear on this, so you 
 shouldn't feel bad about missing this part.  You also had -metadata 
 spontaneously mutate the row data, which is bad.
 
 It's really important for stores to keep their UUID, and for them to hand 
 back the same objectID for an object that they did when we asked before.  
 Otherwise constructing a map from old ids to new ids and looking up stores by 
 their UUID is kinda hard.
 
 I'll send you back the original and edited sample projects so you can diff 
 them.
 
 - Ben
 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com



Re: Two text fields, one outlet?

2010-04-03 Thread Charles Srstka
On Apr 3, 2010, at 6:22 PM, Jenny M wrote:

 Is it possible to link multiple NSTextFields to one outlet? I have
 three views - one of A items, one of B items, and one of both A and B
 items. So the text boxes in the A view also exists in the AB view,
 and the value needs to be able to appear in both, though not at the
 same time. I have a method that calculates values and sets the textbox
 values (or label values, same concept) using an outlet, but I don't
 want it to set 2 outlets, I want it to just set 1.
 
 Is this possible using outlets or bindings??
 
 Or is there a way I can place two NSViews into one NSView so there's
 only one copy of everything?

Instead of fretting about the views, just make two NSString (or 
NSAttributedString) properties in some object. Then make an NSObjectController 
with that object as its “content” outlet, and bind all the “A” views to the “A” 
property and the “B” views to the “B” property. This way the views will always 
be synced up, but you won’t have to bother with outlets at all.

Charles___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Invalidated managed objects

2010-04-03 Thread Ben Trumbull

On Apr 3, 2010, at 9:44 PM, Gideon King wrote:

 Excellent, thanks for that. I thought that once a managed object ID had been 
 assigned, that newReferenceObjectForManagedObject: should always return the 
 same value, so I was regenerating it from the previous data instead of 
 generating a new one if it either had a temporary object id or no object id. 
 I will switch over my code to do this.

Uhm, that's not exactly what I said.  It should look something like:

- (id)newReferenceObjectForManagedObject:(NSManagedObject *)managedObject {
id result = nil;
NSManagedObjectID* oid = [managedObject objectID];
if ((oid == nil) || [oid isTemporaryID]) {
CFUUIDRef uuidRef = CFUUIDCreate(NULL);
CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef);
result = [[NSString alloc] 
initWithString:(NSString*)uuidStringRef];
CFRelease(uuidStringRef);
CFRelease(uuidRef); 
} else {
result = [[self referenceObjectForObjectID:oid] retain];
}
return result;  
}

although all the Core Data stores use a single 64 bit integer with the current 
seed value stored in the metadata instead of UUIDs.

 In my current implementation, I have a base class for all my managed objects 
 that has an id string (elementID) set in it. The only times it is persisted 
 is for objects that I need to refer to in relationships. This means I can 
 regenerate the value from the managed objects if necessary, so my new method 
 will look like this:

The objectID value (referenceObject) needs to be the same every time you load 
the document.  If you open the document multiple times, and give the same 
objects different objectIDs, badness happens.  For Save As, we're generating a 
dictionary of old IDs - new IDs.  When we add the new store to the 
coordinator, if the store hands back random values for the migrated objects, 
then the MOC can't fix its MOs to point to the new store's cache nodes.

if you:

(1) open the document 
(2)  fetch all the objects into array 'results' (with a sort ordering)
(3) NSLog(@results = %@, [results valueForKey:@objectID]), 
(4) close the document
(5) repeat steps 1-4
(6) compare the 2 logs 

If the strings don't match, you're SOL.

 There is only one area of my code where this will cause an issue, where I 
 pre-generate some of the xml for my file using some references to some 
 managed objects. I'm sure I'll be able to find a way around this though.
 
 Hopefully that will resolve that issue.
 
 Also, I had not noticed the loadMetadata: method, so was just creating it in 
 the init for new files, or in my load method for existing ones. I will have 
 to do a bit of work to change that to load using loadMetadata: since I will 
 have to extract the file from a zip file separately from the main load method 
 which already unzips to a temporary folder. Not a biggie though.


You don't have to use it, but for the sample project you sent that conflated 
the metadata and raw data, it was the best way to avoid nuking the already 
loaded metadata when you loaded the raw data.  It's probably all around better 
though.

- Ben



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Invalidated managed objects

2010-04-03 Thread Gideon King
Ah, so when it says the method must derive the reference object from the 
managed object’s values it is talking about the managed object's persisted 
values. So I could get rid of my extra attribute in my managed object class and 
just set my UUID using a method similar to what you define below, and then just 
persist that on all my objects. 

It is possible that the file could be edited in the Windows version of the 
application, or may be imported through an importer that doesn't add the IDs, 
but I guess that wouldn't matter since I would set it the first time it was 
asked for, and I would persist it after that.

Regards

Gideon

 
 The objectID value (referenceObject) needs to be the same every time you 
 load the document.  If you open the document multiple times, and give the 
 same objects different objectIDs, badness happens.  For Save As, we're 
 generating a dictionary of old IDs - new IDs.  When we add the new store to 
 the coordinator, if the store hands back random values for the migrated 
 objects, then the MOC can't fix its MOs to point to the new store's cache 
 nodes.
 
 if you:
 
 (1) open the document 
 (2)  fetch all the objects into array 'results' (with a sort ordering)
 (3) NSLog(@results = %@, [results valueForKey:@objectID]), 
 (4) close the document
 (5) repeat steps 1-4
 (6) compare the 2 logs 
 
 If the strings don't match, you're SOL.
 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com