Sunday, January 12, 2014

ios data archiving issues

Ask a question:
When we put data archiving, CGPoint class can archive it? There are those custom drawing class can also contain image archive it, how archival storage.
Reply:
Objects can archive you can look NSObject + Autocoding this class to all types of archives
Reply:
cited a floor ran0809 reply:
object can archive you can look NSObject + Autocoding this class to all types of archives

There are no related articles or refer to the following code ah?
Reply:

Reply:
reference to the third floor yang8456211 reply:

Yang ~ ~ ~ ~ ~ ~ ~ ~ cry ~ ~ ~ ~ ~ ~ ~ ~ ~
Reply:
reference to the second floor jingtingmeihao reply:
Quote: references to a floor ran0809 reply:

Objects can archive you can look NSObject + Autocoding this class to all types of archives

There are no related articles or refer to the following code ah?


CGPoint package you will be able to NSValue Lane
Reply:

Reply:
Are you asking CGPoint with UIImage archive it, just wrote a demo can ah.

1) inside a custom class inherits NSCoding with NSCopying, your point would be defined as NSValue.
@ Property (copy, nonatomic) UIImage * image;
@ Property (copy, nonatomic) NSValue * point;

2) when it filed with encodeObject
[Encoder encodeObject: image forKey: @ "ImageKey"];
[Encoder encodeObject: point forKey: @ "PointKey"];

3) when stored
CGPoint point = CGPointMake (1.1, 2.2);
NSValue * value = [NSValue valueWithCGPoint: point];

/ / Store the data to the class
Archive * archivingData = [[Archive alloc] init];
archivingData.image = [UIImage imageNamed: @ "pic.jpg"];
archivingData.point = value;

NSMutableData * data = [[NSMutableData alloc] init];

NSKeyedArchiver * archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData: data];
[Archiver encodeObject: archivingData forKey: @ "ArchivingData"];
[Archiver finishEncoding];

/ / Write to file
[Data writeToFile: self.archivingFileRootPath atomically: YES] ;/ / archivingFileRootPath is saved path

4) obtained when
NSData * data = [[NSMutableData alloc] initWithContentsOfFile: self archivingFileRootPath.];
NSKeyedUnarchiver * unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData: data];

/ / Get the class
Archive * archivingData = [unarchiver decodeObjectForKey: @ "ArchivingData"];
[Unarchiver finishDecoding];
self.imageView.image = archivingData.image;
NSValue * value = archivingData.point;
CGPoint point = [value CGPointValue];
NSLog (@ "% f | |% f", point.x, point.y);


Of course, if you are doing the game, I suggest you put all those CGPoint NSArray inside it (into NSValue)
Reply:
reference to the 7th floor yang8456211 reply:
you are asking CGPoint with UIImage archive it, just wrote a demo can ah.

1) inside a custom class inherits NSCoding with NSCopying, your point would be defined as NSValue.
@ Property (copy, nonatomic) UIImage * image;
@ Property (copy, nonatomic) NSValue * point;

2) when it filed with encodeObject
[Encoder encodeObject: image forKey: @ "ImageKey"];
[Encoder encodeObject: point forKey: @ "PointKey"];

3) when stored
CGPoint point = CGPointMake (1.1, 2.2);
NSValue * value = [NSValue valueWithCGPoint: point];

/ / Store the data to the class
Archive * archivingData = [[Archive alloc] init];
archivingData.image = [UIImage imageNamed: @ "pic.jpg"];
archivingData.point = value;

NSMutableData * data = [[NSMutableData alloc] init];

NSKeyedArchiver * archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData: data];
[Archiver encodeObject: archivingData forKey: @ "ArchivingData"];
[Archiver finishEncoding];

/ / Write to file
[Data writeToFile: self.archivingFileRootPath atomically: YES] ;/ / archivingFileRootPath is saved path

4) obtained when
NSData * data = [[NSMutableData alloc] initWithContentsOfFile: self archivingFileRootPath.];
NSKeyedUnarchiver * unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData: data];

/ / Get the class
Archive * archivingData = [unarchiver decodeObjectForKey: @ "ArchivingData"];
[Unarchiver finishDecoding];
self.imageView.image = archivingData.image;
NSValue * value = archivingData.point;
CGPoint point = [value CGPointValue];
NSLog (@ "% f | |% f", point.x, point.y);


Of course, if you are doing the game, I suggest you put all those CGPoint NSArray inside it (into NSValue)


Thank Yang
Reply:
reference to the 8th floor jingtingmeihao reply:
Quote: references to the 7th floor yang8456211 reply:

Are you asking CGPoint with UIImage archive it, just wrote a demo can ah.

1) inside a custom class inherits NSCoding with NSCopying, your point would be defined as NSValue.
@ Property (copy, nonatomic) UIImage * image;
@ Property (copy, nonatomic) NSValue * point;

2) when it filed with encodeObject
[Encoder encodeObject: image forKey: @ "ImageKey"];
[Encoder encodeObject: point forKey: @ "PointKey"];

3) when stored
CGPoint point = CGPointMake (1.1, 2.2);
NSValue * value = [NSValue valueWithCGPoint: point];

/ / Store the data to the class
Archive * archivingData = [[Archive alloc] init];
archivingData.image = [UIImage imageNamed: @ "pic.jpg"];
archivingData.point = value;

NSMutableData * data = [[NSMutableData alloc] init];

NSKeyedArchiver * archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData: data];
[Archiver encodeObject: archivingData forKey: @ "ArchivingData"];
[Archiver finishEncoding];

/ / Write to file
[Data writeToFile: self.archivingFileRootPath atomically: YES] ;/ / archivingFileRootPath is saved path

4) obtained when
NSData * data = [[NSMutableData alloc] initWithContentsOfFile: self archivingFileRootPath.];
NSKeyedUnarchiver * unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData: data];

/ / Get the class
Archive * archivingData = [unarchiver decodeObjectForKey: @ "ArchivingData"];
[Unarchiver finishDecoding];
self.imageView.image = archivingData.image;
NSValue * value = archivingData.point;
CGPoint point = [value CGPointValue];
NSLog (@ "% f | |% f", point.x, point.y);


Of course, if you are doing the game, I suggest you put all those CGPoint NSArray inside it (into NSValue)


Thank Yang
say ~
Reply:
reference to the third floor yang8456211 reply:

Yang brother, ask you a question ah ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Can you tell me your QQ? I asked you a very stupid question, I do not ~ ~ ~ ~ ~ ~ ~ ~ recently doing the project, Kusi ~ ~ ~ ~ ~ ~ ~ ~ better not ah
Reply:
reference to the 6th floor u012668981 reply:

Yang brother ~ ~ ~ ~ ~ ~ Reply me back my ~ ~ ~ ~ ~ ~ ~
Reply:
reference to the 11th floor jingtingmeihao reply:
Quote: references to the 6th floor u012668981 reply:


Yang brother ~ ~ ~ ~ ~ ~ Reply me back my ~ ~ ~ ~ ~ ~ ~

- 347702498 What is the problem message, and I do not work when the q's. . Generally free
night

No comments:

Post a Comment