开发者

Better approach to Serializing tree node

开发者 https://www.devze.com 2023-03-28 10:23 出处:网络
I need to Serialize tree node, as of now I did not find any way to write reference to parent node point using object serializing using NSCoding protocol

I need to Serialize tree node, as of now I did not find any way to write reference to parent node point using object serializing using NSCoding protocol

My node class开发者_StackOverflow社区

@interface FNode : NSObject 
{
@private
    NSString* name;
    NSObject* data;

    FNode* parent;
    NSMutableDictionary* childs;
}

@property (retain) NSString* name;
@property (retain) NSObject* data;

@property (assign)FNode* parent;
@property (retain)NSMutableDictionary* childs;

@end

As of now I create all data in tree as a NSArray before I encode it and in decoding I take NSArray of data and create the tree.

I am just wondering is there any better approach to this problem … I appreciate your thought.


Why do you build that array first? Each node should know about encoding itself including the childs (but not the parent, because you would have a loop). TheN you simply encode the tree by storing the root node. That encodes the whole tree.

While decoding, you can set the parent reference.

0

精彩评论

暂无评论...
验证码 换一张
取 消