Re: Question about Archives and Serialisations Programming Guide

2016-02-05 Thread Jean-Daniel Dupas
Maybe an issue cause you use __weak reference which zeroed for some reason.
Can you try to use __unsafe_unretained instead and see what happen ?

> Le 5 févr. 2016 à 14:46, Dave  a écrit :
> 
> 
>> On 5 Feb 2016, at 13:34, Jean-Daniel Dupas  wrote:
>> 
>> And obviously, you also add - encodeWithCoder: and -initWithCoder: methods 
>> in your custom classes.
> 
> Yes, see my other thread, it decodes all the other fields but not the (weak) 
> back links get set to nil most of the time…….
> ___
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/mailing%40xenonium.com
> 
> This email sent to mail...@xenonium.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: Question about Archives and Serialisations Programming Guide

2016-02-05 Thread Quincey Morris
On Feb 5, 2016, at 07:27 , Dave  wrote:
> 
> If you set it strong, then it creates a dupe of the object over and over 
> again, as I said in the other thread

a. If that’s the case, then your problem is nothing to do with the weak 
references. Something is causing those objects to be *either* archived as 
unique objects (copies) *or* copied after unarchiving. As others have 
repeatedly stated, object uniqueness *is* maintained through archiving and 
unarchiving, and if you’re following the idea that there’s something wrong with 
NSKeyedArchiver/NSKeyedUnarchiver, then you’re almost certainly barking up the 
wrong tree.

Your first task, therefore, is to find out whether copies of the object are 
being archived, or whether copies are being made after unarchiving.

(Here’s one scenario where it might happen on unarchiving: if some relevant 
property is marked ‘copy’. In that case, you need to ensure that in 
initWithCoder you store unarchived references into the instance variable, and 
not store them via the property. I doubt the real answer is that easy, but 
that’s the sort of thing to look for.)

b. There is no problem with archiving weak references. I’ve done it (for parent 
references in a hierarchical tree structure). Even though I don’t have the 
implementations of NSKeyedArchiver/NSKeyedUnarchiver, they have to work because 
they don’t *know* the objects being archived or unarchived are “weak”, because 
*objects* are not weak, only references to objects.

All the references to objects within NSKeyedArchiver/NSKeyedUnarchiver are 
strong. That’s why those classes have the idea of “conditional” objects, which 
is their mechanism for handling objects that are only weakly referenced in the 
part of an object graph that’s being archived and unarchived (and presumably 
strongly referenced only by transient references that don’t go into the 
archive).
___

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

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

Re: Question about Archives and Serialisations Programming Guide

2016-02-05 Thread Alex Zavatone

On Feb 5, 2016, at 8:46 AM, Dave wrote:

> 
>> On 5 Feb 2016, at 13:34, Jean-Daniel Dupas  wrote:
>> 
>> And obviously, you also add - encodeWithCoder: and -initWithCoder: methods 
>> in your custom classes.
> 
> Yes, see my other thread, it decodes all the other fields but not the (weak) 
> back links get set to nil most of the time…….

Ahhh.

It would seem that the reference is being lost when the archiving happens.

Would something that is the opposite of strongify/weakify work here?  Sort of a 
strongify a weak reference when it comes to archiving and archive the strong 
reference?

That almost sounds crazy enough to work.

> ___
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com
> 
> This email sent to z...@mac.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: Question about Archives and Serialisations Programming Guide

2016-02-05 Thread Dave
> 
> Would something that is the opposite of strongify/weakify work here?  Sort of 
> a strongify a weak reference when it comes to archiving and archive the 
> strong reference?

Sort of a Quantum reference! 

> That almost sounds crazy enough to work.

So do Quantum computers!





___

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

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

Re: Question about Archives and Serialisations Programming Guide

2016-02-05 Thread Dave

> On 5 Feb 2016, at 15:07, Jean-Daniel Dupas  wrote:
> 
> Maybe an issue cause you use __weak reference which zeroed for some reason.
> Can you try to use __unsafe_unretained instead and see what happen ?

If you look on my other thread, you will see that I have tried this, if I use 
“assign” or _unsafe_unretained it crashes when unarchiving that object.

If you set it strong, then it creates a dupe of the object over and over again, 
as I said in the other thread, when I changed things a bit and, I get one level 
where the parent is referenced (e.g. root to first level child) and the rest 
nil……

Cheers
Dave


___

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

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

Re: Question about Archives and Serialisations Programming Guide

2016-02-05 Thread Dave
Hi Alex,

Found it! Well, Jean-Daniel did - Thanks again!

I was barking up the wrong tree thinking it was the back links that were the 
problem. Using weak caused them to (correctly as it turned out) be set to nil 
when the node it reference is released. The problem was in the initWithCoder 
method, I was using:

self.pNetworkNodeChildArray = [[NSMutableArray alloc] initWithArray:myArray 
copyItems:YES];

and that should be - copyItems:NO

I’m not sure where I got the YES from, I think it was from a very simple 
example I found online. Anyway if you set it to NO, it works as expected.

Worth checking if you have this too when you shouldn’t. 

AFAIK, there are no working examples of using a back link like this, if anyone 
wants to post my sample code to their web-site they are welcome to it, just 
drop me a line.

All the Best
Dave

> On 5 Feb 2016, at 16:37, Alex Zavatone  wrote:
> 
> 
> On Feb 5, 2016, at 8:46 AM, Dave wrote:
> 
>> 
>>> On 5 Feb 2016, at 13:34, Jean-Daniel Dupas  wrote:
>>> 
>>> And obviously, you also add - encodeWithCoder: and -initWithCoder: methods 
>>> in your custom classes.
>> 
>> Yes, see my other thread, it decodes all the other fields but not the (weak) 
>> back links get set to nil most of the time…….
> 
> Ahhh.
> 
> It would seem that the reference is being lost when the archiving happens.
> 
> Would something that is the opposite of strongify/weakify work here?  Sort of 
> a strongify a weak reference when it comes to archiving and archive the 
> strong reference?
> 
> That almost sounds crazy enough to work.
> 
>> ___
>> 
>> 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:
>> https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com
>> 
>> This email sent to z...@mac.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: Question about Archives and Serialisations Programming Guide

2016-02-05 Thread Dave

> On 5 Feb 2016, at 17:04, Quincey Morris  
> wrote:
> 
> On Feb 5, 2016, at 07:27 , Dave  > wrote:
>> 
>> If you set it strong, then it creates a dupe of the object over and over 
>> again, as I said in the other thread
> 
> a. If that’s the case, then your problem is nothing to do with the weak 
> references. Something is causing those objects to be *either* archived as 
> unique objects (copies) *or* copied after unarchiving. As others have 
> repeatedly stated, object uniqueness *is* maintained through archiving and 
> unarchiving, and if you’re following the idea that there’s something wrong 
> with NSKeyedArchiver/NSKeyedUnarchiver, then you’re almost certainly barking 
> up the wrong tree.

Yes, I didn’t really think it was a problem with 
NSKeyedArchiver/NSKeyedUnarchiver, but I thought there was something more I had 
to do to make it work……. 

Found it now and, your were right, I was using copyItems:YES in the 
initWithCoder which caused new Child Objects to be generated, thus causing the 
weakly referenced back pointers to be zero’ed…..


Thanks for the explanation, I haven’t found anything that states it as 
plainly…..

All the Best
Dave

___

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

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

Re: Question about Archives and Serialisations Programming Guide

2016-02-05 Thread Alex Zavatone
Sure.  That would be nice.

I also recall some classes for archiving and dearchiving that use introspection 
that automatically handle the proper action in one line of code.

For simple cases with straightforward collection classes, this is a really 
really really nice approach and frees us from having to write special case code 
for each property.

Something like automaticInitWithCoder and automaticEncodeWithCoder.

It would be nice if the default operations were able to use Objective-C's 
introspection to achieve this, but well, they don't.

If anyone knows of these more automatic initers and encoders, I'd sure like a 
pointer to them.

Thanks and happy you got it working, Dave.

Alex Zavatone



On Feb 5, 2016, at 12:00 PM, Dave wrote:

> Hi Alex,
> 
> Found it! Well, Jean-Daniel did - Thanks again!
> 
> I was barking up the wrong tree thinking it was the back links that were the 
> problem. Using weak caused them to (correctly as it turned out) be set to nil 
> when the node it reference is released. The problem was in the initWithCoder 
> method, I was using:
> 
> self.pNetworkNodeChildArray = [[NSMutableArray alloc] initWithArray:myArray 
> copyItems:YES];
> 
> and that should be - copyItems:NO
> 
> I’m not sure where I got the YES from, I think it was from a very simple 
> example I found online. Anyway if you set it to NO, it works as expected.
> 
> Worth checking if you have this too when you shouldn’t. 
> 
> AFAIK, there are no working examples of using a back link like this, if 
> anyone wants to post my sample code to their web-site they are welcome to it, 
> just drop me a line.
> 
> All the Best
> Dave
> 
>> On 5 Feb 2016, at 16:37, Alex Zavatone  wrote:
>> 
>> 
>> On Feb 5, 2016, at 8:46 AM, Dave wrote:
>> 
>>> 
 On 5 Feb 2016, at 13:34, Jean-Daniel Dupas  wrote:
 
 And obviously, you also add - encodeWithCoder: and -initWithCoder: methods 
 in your custom classes.
>>> 
>>> Yes, see my other thread, it decodes all the other fields but not the 
>>> (weak) back links get set to nil most of the time…….
>> 
>> Ahhh.
>> 
>> It would seem that the reference is being lost when the archiving happens.
>> 
>> Would something that is the opposite of strongify/weakify work here?  Sort 
>> of a strongify a weak reference when it comes to archiving and archive the 
>> strong reference?
>> 
>> That almost sounds crazy enough to work.
>> 
>>> ___
>>> 
>>> 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:
>>> https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com
>>> 
>>> This email sent to z...@mac.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:
> https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com
> 
> This email sent to z...@mac.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: Question about Archives and Serialisations Programming Guide

2016-02-05 Thread Alex Zavatone

On Feb 5, 2016, at 12:01 PM, Dave wrote:

>> 
>> Would something that is the opposite of strongify/weakify work here?  Sort 
>> of a strongify a weak reference when it comes to archiving and archive the 
>> strong reference?
> 
> Sort of a Quantum reference! 
> 
>> That almost sounds crazy enough to work.
> 
> So do Quantum computers!

Next thing you know, this so called "Internet" thing will take off and people 
will be walking around with "iPhones" in their pockets.

That'll be the 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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: Question about Archives and Serialisations Programming Guide

2016-02-05 Thread Graham Cox

> On 6 Feb 2016, at 4:00 AM, Dave  wrote:
> 
> self.pNetworkNodeChildArray = [[NSMutableArray alloc] initWithArray:myArray 
> copyItems:YES];


This is one reason why sometimes having explicit ivars for key parts of an 
object will save you many hours of trouble.

If you had e.g:

@synthesize pNetworkChildArray = mChildArray; // mChildArray is an ivar 
NSMutableArray*

your -initWithCoder: method could then do something simple like:

mChildArray = [[aDecoder decodeObjectForKey:@“children”] mutableCopy];

This will avoid all of the issues you’ve had and also give you better 
performance, because it’s not invoking a setter method, nor allocating an 
unneeded intermediate copy of the array. For large object graphs, (>10,000 
nodes say) bypassing a property setter can end up shaving minutes off the time 
to decode an archive. - initWithCoder: is an init method, it should be creating 
the initial state of the object, incuding allocating its ivars. So you don’t 
have to either a) allocate the ivars then copy the decoded array into them, nor 
b) worry about a leak caused by simply assigning a mutable copy of a decoded 
array to the ivar. Another benefit of this is that you could declare your 
pNetworkChildArray property read-only and non-mutable in the public interface, 
which would catch external abuses of the network - usually only the internals 
of the tree itself have any business mutating this.

n.b. if you’d have shown your code rather than a long verbal description of 
what you were doing, the problem would have been instantly obvious. For 
comparison, here’s the -initWithCoder: method I have in a general purpose tree 
node class. It has never given the slightest trouble:

#pragma mark - NSCoding

- (instancetype) initWithCoder:(NSCoder*) aDecoder
{
self = [super init];
if( self )
{
mChildNodes = [[aDecoder decodeObjectForKey:@"Node_children"] 
mutableCopy];
mParentNode = [aDecoder decodeObjectForKey:@"Node_parent"];
mRepresentedObject = [[aDecoder 
decodeObjectForKey:@"Node_payload"] retain];
}

return self;
}




___

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

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

Question about Archives and Serialisations Programming Guide

2016-02-05 Thread Dave
Hi,

I’m having problems with Back Links when Archiving/Unarchiving an Object. I 
found the text below at:

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Archiving/Articles/archives.html


Root Object

An object graph is not necessarily a simple tree structure. Two objects can 
contain references to each other, for example, creating a cycle. If a coder 
follows every link and blindly encodes each object it encounters, this circular 
reference will generate an infinite loop in the coder. Also, a single object 
can be referenced by several other objects. The coder must be able to recognize 
and handle multiple and circular references so that it does not encode more 
than one copy of each object, but still regenerate all the references when 
decoding.
To solve this problem, NSCoder introduces the concept of a root object. The 
root object is the starting point of an object graph. To encode an object 
graph, you invoke the NSCoder method encodeRootObject:, passing in the first 
object to encode. Every object encoded within the context of this invocation is 
tracked. If the coder is asked to encode an object more than once, the coder 
encodes a reference to the first encoding instead of encoding the object again.

NSCoder does not implement support for root objects; NSCoder’s implementation 
of encodeRootObject: simply encodes the object by invoking encodeObject:. It is 
the responsibility of its concrete subclasses to keep track of multiple 
references to objects, thus preserving the structure of any object graphs.

The last paragraph seems pertinent to my problem, so do I need to do something 
special for “weak”, back links in order to “keep track of multiple references 
to objects”? If so could some please tell me how to do this? I’m really 
struggling to get something out the door and was advised to use the Keyed 
Archiver/Unarchiver as it would be the simplest implementation……

Is this any other documentation or sample code available? There are plenty of 
trivial examples out there, no nothing I can find that works for weak back 
links, although according to all the Apple Blurb I can find, it is possible, 
they just don’t tell you how to do it that I can find!

Thanks in Advance for Any Help
All the Best
Dave

___

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

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

Re: Question about Archives and Serialisations Programming Guide

2016-02-05 Thread Jean-Daniel Dupas
That is your need, not your problem. 

To archive an object graph (cyclic or not), you just do [NSKeyedArchiver 
archiveRootObject:graph toFile:@"myfile"];



> Le 5 févr. 2016 à 14:28, Dave  a écrit :
> 
> Hi,
> 
> See my other thread on this list which explains it fully  - 
> "Archive/Unarchive Problem/Question?”.
> 
> Basically I need to save/restore a Network of Custom Objects…..
> 
> All the Best
> Dave
> 
>> On 5 Feb 2016, at 13:18, Jean-Daniel Dupas  wrote:
>> 
>> You don’t tell use what is your problem. You can perfectly encode any 
>> structure using Keyed archivers (whether there is cycles and backlinks).
>> 
>>> Le 5 févr. 2016 à 14:13, Dave  a écrit :
>>> 
>>> Hi,
>>> 
>>> I’m having problems with Back Links when Archiving/Unarchiving an Object. I 
>>> found the text below at:
>>> 
>>> https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Archiving/Articles/archives.html
>>> 
>>> 
>>> Root Object
>>> 
>>> An object graph is not necessarily a simple tree structure. Two objects can 
>>> contain references to each other, for example, creating a cycle. If a coder 
>>> follows every link and blindly encodes each object it encounters, this 
>>> circular reference will generate an infinite loop in the coder. Also, a 
>>> single object can be referenced by several other objects. The coder must be 
>>> able to recognize and handle multiple and circular references so that it 
>>> does not encode more than one copy of each object, but still regenerate all 
>>> the references when decoding.
>>> To solve this problem, NSCoder introduces the concept of a root object. The 
>>> root object is the starting point of an object graph. To encode an object 
>>> graph, you invoke the NSCoder method encodeRootObject:, passing in the 
>>> first object to encode. Every object encoded within the context of this 
>>> invocation is tracked. If the coder is asked to encode an object more than 
>>> once, the coder encodes a reference to the first encoding instead of 
>>> encoding the object again.
>>> 
>>> NSCoder does not implement support for root objects; NSCoder’s 
>>> implementation of encodeRootObject: simply encodes the object by invoking 
>>> encodeObject:. It is the responsibility of its concrete subclasses to keep 
>>> track of multiple references to objects, thus preserving the structure of 
>>> any object graphs.
>>> 
>>> The last paragraph seems pertinent to my problem, so do I need to do 
>>> something special for “weak”, back links in order to “keep track of 
>>> multiple references to objects”? If so could some please tell me how to do 
>>> this? I’m really struggling to get something out the door and was advised 
>>> to use the Keyed Archiver/Unarchiver as it would be the simplest 
>>> implementation……
>>> 
>>> Is this any other documentation or sample code available? There are plenty 
>>> of trivial examples out there, no nothing I can find that works for weak 
>>> back links, although according to all the Apple Blurb I can find, it is 
>>> possible, they just don’t tell you how to do it that I can find!
>>> 
>>> Thanks in Advance for Any Help
>>> All the Best
>>> Dave
>>> 
>>> ___
>>> 
>>> 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:
>>> https://lists.apple.com/mailman/options/cocoa-dev/mailing%40xenonium.com
>>> 
>>> This email sent to mail...@xenonium.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:
> https://lists.apple.com/mailman/options/cocoa-dev/mailing%40xenonium.com
> 
> This email sent to mail...@xenonium.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: Question about Archives and Serialisations Programming Guide

2016-02-05 Thread Jean-Daniel Dupas
And obviously, you also add - encodeWithCoder: and -initWithCoder: methods in 
your custom classes.

> Le 5 févr. 2016 à 14:33, Jean-Daniel Dupas  a écrit :
> 
> That is your need, not your problem. 
> 
> To archive an object graph (cyclic or not), you just do [NSKeyedArchiver 
> archiveRootObject:graph toFile:@"myfile"];
> 
> 
> 
>> Le 5 févr. 2016 à 14:28, Dave  a écrit :
>> 
>> Hi,
>> 
>> See my other thread on this list which explains it fully  - 
>> "Archive/Unarchive Problem/Question?”.
>> 
>> Basically I need to save/restore a Network of Custom Objects…..
>> 
>> All the Best
>> Dave
>> 
>>> On 5 Feb 2016, at 13:18, Jean-Daniel Dupas  wrote:
>>> 
>>> You don’t tell use what is your problem. You can perfectly encode any 
>>> structure using Keyed archivers (whether there is cycles and backlinks).
>>> 
 Le 5 févr. 2016 à 14:13, Dave  a écrit :
 
 Hi,
 
 I’m having problems with Back Links when Archiving/Unarchiving an Object. 
 I found the text below at:
 
 https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Archiving/Articles/archives.html
 
 
 Root Object
 
 An object graph is not necessarily a simple tree structure. Two objects 
 can contain references to each other, for example, creating a cycle. If a 
 coder follows every link and blindly encodes each object it encounters, 
 this circular reference will generate an infinite loop in the coder. Also, 
 a single object can be referenced by several other objects. The coder must 
 be able to recognize and handle multiple and circular references so that 
 it does not encode more than one copy of each object, but still regenerate 
 all the references when decoding.
 To solve this problem, NSCoder introduces the concept of a root object. 
 The root object is the starting point of an object graph. To encode an 
 object graph, you invoke the NSCoder method encodeRootObject:, passing in 
 the first object to encode. Every object encoded within the context of 
 this invocation is tracked. If the coder is asked to encode an object more 
 than once, the coder encodes a reference to the first encoding instead of 
 encoding the object again.
 
 NSCoder does not implement support for root objects; NSCoder’s 
 implementation of encodeRootObject: simply encodes the object by invoking 
 encodeObject:. It is the responsibility of its concrete subclasses to keep 
 track of multiple references to objects, thus preserving the structure of 
 any object graphs.
 
 The last paragraph seems pertinent to my problem, so do I need to do 
 something special for “weak”, back links in order to “keep track of 
 multiple references to objects”? If so could some please tell me how to do 
 this? I’m really struggling to get something out the door and was advised 
 to use the Keyed Archiver/Unarchiver as it would be the simplest 
 implementation……
 
 Is this any other documentation or sample code available? There are plenty 
 of trivial examples out there, no nothing I can find that works for weak 
 back links, although according to all the Apple Blurb I can find, it is 
 possible, they just don’t tell you how to do it that I can find!
 
 Thanks in Advance for Any Help
 All the Best
 Dave
 
 ___
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/mailing%40xenonium.com
 
 This email sent to mail...@xenonium.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:
>> https://lists.apple.com/mailman/options/cocoa-dev/mailing%40xenonium.com
>> 
>> This email sent to mail...@xenonium.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: Question about Archives and Serialisations Programming Guide

2016-02-05 Thread Dave
Hi,

> On 5 Feb 2016, at 13:37, Alex Zavatone  wrote:
> 
> The first question is, “Do you have any circular references?”

See my other thread for answer to that, but no, its a network with a Root 
Object and Child Objects, similar to a NSViewController/NSView Hierarchy.

So, no there are no circular references. Each Node has a Child Array and a 
Parent (weak) Back Link.

So:

ObjectX.ChildArray[n].parent == ObjectX //In terms of Pointers.

All the Best
Dave

___

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

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

Re: Question about Archives and Serialisations Programming Guide

2016-02-05 Thread Jean-Daniel Dupas
You don’t tell use what is your problem. You can perfectly encode any structure 
using Keyed archivers (whether there is cycles and backlinks).

> Le 5 févr. 2016 à 14:13, Dave  a écrit :
> 
> Hi,
> 
> I’m having problems with Back Links when Archiving/Unarchiving an Object. I 
> found the text below at:
> 
> https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Archiving/Articles/archives.html
> 
> 
> Root Object
> 
> An object graph is not necessarily a simple tree structure. Two objects can 
> contain references to each other, for example, creating a cycle. If a coder 
> follows every link and blindly encodes each object it encounters, this 
> circular reference will generate an infinite loop in the coder. Also, a 
> single object can be referenced by several other objects. The coder must be 
> able to recognize and handle multiple and circular references so that it does 
> not encode more than one copy of each object, but still regenerate all the 
> references when decoding.
> To solve this problem, NSCoder introduces the concept of a root object. The 
> root object is the starting point of an object graph. To encode an object 
> graph, you invoke the NSCoder method encodeRootObject:, passing in the first 
> object to encode. Every object encoded within the context of this invocation 
> is tracked. If the coder is asked to encode an object more than once, the 
> coder encodes a reference to the first encoding instead of encoding the 
> object again.
> 
> NSCoder does not implement support for root objects; NSCoder’s implementation 
> of encodeRootObject: simply encodes the object by invoking encodeObject:. It 
> is the responsibility of its concrete subclasses to keep track of multiple 
> references to objects, thus preserving the structure of any object graphs.
> 
> The last paragraph seems pertinent to my problem, so do I need to do 
> something special for “weak”, back links in order to “keep track of multiple 
> references to objects”? If so could some please tell me how to do this? I’m 
> really struggling to get something out the door and was advised to use the 
> Keyed Archiver/Unarchiver as it would be the simplest implementation……
> 
> Is this any other documentation or sample code available? There are plenty of 
> trivial examples out there, no nothing I can find that works for weak back 
> links, although according to all the Apple Blurb I can find, it is possible, 
> they just don’t tell you how to do it that I can find!
> 
> Thanks in Advance for Any Help
> All the Best
> Dave
> 
> ___
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/mailing%40xenonium.com
> 
> This email sent to mail...@xenonium.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: Question about Archives and Serialisations Programming Guide

2016-02-05 Thread Dave
Hi,

See my other thread on this list which explains it fully  - "Archive/Unarchive 
Problem/Question?”.

Basically I need to save/restore a Network of Custom Objects…..

All the Best
Dave

> On 5 Feb 2016, at 13:18, Jean-Daniel Dupas  wrote:
> 
> You don’t tell use what is your problem. You can perfectly encode any 
> structure using Keyed archivers (whether there is cycles and backlinks).
> 
>> Le 5 févr. 2016 à 14:13, Dave  a écrit :
>> 
>> Hi,
>> 
>> I’m having problems with Back Links when Archiving/Unarchiving an Object. I 
>> found the text below at:
>> 
>> https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Archiving/Articles/archives.html
>> 
>> 
>> Root Object
>> 
>> An object graph is not necessarily a simple tree structure. Two objects can 
>> contain references to each other, for example, creating a cycle. If a coder 
>> follows every link and blindly encodes each object it encounters, this 
>> circular reference will generate an infinite loop in the coder. Also, a 
>> single object can be referenced by several other objects. The coder must be 
>> able to recognize and handle multiple and circular references so that it 
>> does not encode more than one copy of each object, but still regenerate all 
>> the references when decoding.
>> To solve this problem, NSCoder introduces the concept of a root object. The 
>> root object is the starting point of an object graph. To encode an object 
>> graph, you invoke the NSCoder method encodeRootObject:, passing in the first 
>> object to encode. Every object encoded within the context of this invocation 
>> is tracked. If the coder is asked to encode an object more than once, the 
>> coder encodes a reference to the first encoding instead of encoding the 
>> object again.
>> 
>> NSCoder does not implement support for root objects; NSCoder’s 
>> implementation of encodeRootObject: simply encodes the object by invoking 
>> encodeObject:. It is the responsibility of its concrete subclasses to keep 
>> track of multiple references to objects, thus preserving the structure of 
>> any object graphs.
>> 
>> The last paragraph seems pertinent to my problem, so do I need to do 
>> something special for “weak”, back links in order to “keep track of multiple 
>> references to objects”? If so could some please tell me how to do this? I’m 
>> really struggling to get something out the door and was advised to use the 
>> Keyed Archiver/Unarchiver as it would be the simplest implementation……
>> 
>> Is this any other documentation or sample code available? There are plenty 
>> of trivial examples out there, no nothing I can find that works for weak 
>> back links, although according to all the Apple Blurb I can find, it is 
>> possible, they just don’t tell you how to do it that I can find!
>> 
>> Thanks in Advance for Any Help
>> All the Best
>> Dave
>> 
>> ___
>> 
>> 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:
>> https://lists.apple.com/mailman/options/cocoa-dev/mailing%40xenonium.com
>> 
>> This email sent to mail...@xenonium.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: Question about Archives and Serialisations Programming Guide

2016-02-05 Thread Alex Zavatone
The first question is, “Do you have any circular references?”

On Feb 5, 2016, at 8:13 AM, Dave  wrote:

> Hi,
> 
> I’m having problems with Back Links when Archiving/Unarchiving an Object. I 
> found the text below at:
> 
> https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Archiving/Articles/archives.html
> 
> 
> Root Object
> 
> An object graph is not necessarily a simple tree structure. Two objects can 
> contain references to each other, for example, creating a cycle. If a coder 
> follows every link and blindly encodes each object it encounters, this 
> circular reference will generate an infinite loop in the coder. Also, a 
> single object can be referenced by several other objects. The coder must be 
> able to recognize and handle multiple and circular references so that it does 
> not encode more than one copy of each object, but still regenerate all the 
> references when decoding.
> To solve this problem, NSCoder introduces the concept of a root object. The 
> root object is the starting point of an object graph. To encode an object 
> graph, you invoke the NSCoder method encodeRootObject:, passing in the first 
> object to encode. Every object encoded within the context of this invocation 
> is tracked. If the coder is asked to encode an object more than once, the 
> coder encodes a reference to the first encoding instead of encoding the 
> object again.
> 
> NSCoder does not implement support for root objects; NSCoder’s implementation 
> of encodeRootObject: simply encodes the object by invoking encodeObject:. It 
> is the responsibility of its concrete subclasses to keep track of multiple 
> references to objects, thus preserving the structure of any object graphs.
> 
> The last paragraph seems pertinent to my problem, so do I need to do 
> something special for “weak”, back links in order to “keep track of multiple 
> references to objects”? If so could some please tell me how to do this? I’m 
> really struggling to get something out the door and was advised to use the 
> Keyed Archiver/Unarchiver as it would be the simplest implementation……
> 
> Is this any other documentation or sample code available? There are plenty of 
> trivial examples out there, no nothing I can find that works for weak back 
> links, although according to all the Apple Blurb I can find, it is possible, 
> they just don’t tell you how to do it that I can find!
> 
> Thanks in Advance for Any Help
> All the Best
> Dave
> 
> ___
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com
> 
> This email sent to z...@mac.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: Question about Archives and Serialisations Programming Guide

2016-02-05 Thread Dave

> On 5 Feb 2016, at 13:34, Jean-Daniel Dupas  wrote:
> 
> And obviously, you also add - encodeWithCoder: and -initWithCoder: methods in 
> your custom classes.

Yes, see my other thread, it decodes all the other fields but not the (weak) 
back links get set to nil most of the time…….
___

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

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

Re: Question about Archives and Serialisations Programming Guide

2016-02-05 Thread Jens Alfke

> On Feb 5, 2016, at 9:00 AM, Dave  wrote:
> 
> self.pNetworkNodeChildArray = [[NSMutableArray alloc] initWithArray:myArray 
> copyItems:YES];
> 
> and that should be - copyItems:NO

Or just myArray.mutableCopy …

—Jens
___

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

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