• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            大龍的博客

            常用鏈接

            統計

            最新評論

            copyWithZone --- 轉

            iphone歸檔

              歸檔指的是另一種型式的序列化,但它是任保對象都可以實現的更常規的類型。
             
              其作用為:進行數據的持久化保存。
             
              對象必須實現NSCodeing協議和NSCopying協議。
             
            @interface FourLines : NSObject <NSCoding, NSCopying> {
                NSString *field1;
                NSString *field2;
                NSString *field3;
                NSString *field4;   
            }
            @property (nonatomic, retain) NSString *field1;
            @property (nonatomic, retain) NSString *field2;
            @property (nonatomic, retain) NSString *field3;
            @property (nonatomic, retain) NSString *field4;
            @end
            #pragma mark NSCoding
            - (void)encodeWithCoder:(NSCoder *)encoder {
                [encoder encodeObject:field1 forKey:kField1Key];
                [encoder encodeObject:field2 forKey:kField2Key];
                [encoder encodeObject:field3 forKey:kField3Key];
                [encoder encodeObject:field4 forKey:kField4Key];
            }
            - (id)initWithCoder:(NSCoder *)decoder {
                if (self = [super init]) {
                    self.field1 = [decoder decodeObjectForKey:kField1Key];
                    self.field2 = [decoder decodeObjectForKey:kField2Key];
                    self.field3 = [decoder decodeObjectForKey:kField3Key];
                    self.field4 = [decoder decodeObjectForKey:kField4Key];
                }
                return self;
            }
            #pragma mark NSCopying
            - (id)copyWithZone:(NSZone *)zone {
                FourLines *copy = [[[self class] allocWithZone: zone] init];
                copy.field1 = [[self.field1 copyWithZone:zone] autorelease];
                copy.field2 = [[self.field2 copyWithZone:zone] autorelease];
                copy.field3 = [[self.field3 copyWithZone:zone] autorelease];
                copy.field4 = [[self.field4 copyWithZone:zone] autorelease];
               
                return copy;
            }
             
             
             
            獲取歸檔文件
             
            - (NSString *)dataFilePath {
                NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
                NSString *documentsDirectory = [paths objectAtIndex:0];
                return [documentsDirectory stringByAppendingPathComponent:@"archive"];
            }
             
             
            對數據進行歸檔
             
            FourLines *fourLines = [[FourLines alloc] init];
                fourLines.field1 = field1.text;
                fourLines.field2 = field2.text;
                fourLines.field3 = field3.text;
                fourLines.field4 = field4.text;
               
            //對數據進行歸檔
                NSMutableData *data = [[NSMutableData alloc] init];
                NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
                [archiver encodeObject:fourLines forKey:@"Data"];
                [archiver finishEncoding];
                [data writeToFile:[self dataFilePath] atomically:YES];
                [fourLines release];
                [archiver release];
                [data release];   
             
             
             
            獲取歸檔數據
             
                NSString *filePath = [self dataFilePath];
                if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
                    NSData *data = [[NSMutableData alloc]
                                    initWithContentsOfFile:[self dataFilePath]];
                    NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc]
                                                     initForReadingWithData:data];
                    FourLines *fourLines = [unarchiver decodeObjectForKey:@"Data"];
                    [unarchiver finishDecoding];
                   
                    field1.text = fourLines.field1;
                    field2.text = fourLines.field2;
                    field3.text = fourLines.field3;
                    field4.text = fourLines.field4;
                   
                    [unarchiver release];
                    [data release];       
                }
             

            @import url(http://www.shnenglu.com/cutesoft_client/cuteeditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);

            posted on 2013-02-20 17:14 大龍 閱讀(1265) 評論(0)  編輯 收藏 引用

            国产成人精品综合久久久| 91精品国产综合久久四虎久久无码一级 | 久久久久人妻精品一区| 69国产成人综合久久精品| 777久久精品一区二区三区无码 | 久久91精品国产91久久小草| 久久99国产精品久久99| 青草久久久国产线免观| 亚洲精品无码久久一线| 久久se精品一区精品二区国产| 久久无码高潮喷水| 精品久久久久久亚洲| 欧美久久久久久午夜精品| 欧美喷潮久久久XXXXx| 久久天天躁狠狠躁夜夜av浪潮| 奇米影视7777久久精品| 久久青青草原精品国产软件| 国内精品久久久久影院优| 亚洲а∨天堂久久精品| 青青草国产成人久久91网| 久久人妻AV中文字幕| 久久精品国产一区二区电影| 久久亚洲精品人成综合网| 亚洲国产天堂久久久久久| 国产精品亚洲美女久久久| 久久精品国产亚洲AV嫖农村妇女 | 少妇久久久久久被弄到高潮| 久久久久高潮毛片免费全部播放 | 性欧美大战久久久久久久| 一本大道加勒比久久综合| 国产午夜精品久久久久免费视| 一级做a爰片久久毛片免费陪| 国产免费久久精品丫丫| 免费观看久久精彩视频| 国产精品99精品久久免费| 久久久久AV综合网成人 | www性久久久com| 亚洲va中文字幕无码久久不卡| 久久热这里只有精品在线观看| 久久久久久久91精品免费观看| 污污内射久久一区二区欧美日韩|