• <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 大龍 閱讀(1267) 評論(0)  編輯 收藏 引用

            国产精品99久久久久久董美香| 国产精品美女久久久免费| 久久成人国产精品免费软件| 国产精品久久久久久久app| 伊人久久大香线焦AV综合影院 | 久久这里都是精品| 一本色道久久99一综合| 国产精品成人久久久久久久| 久久久久久久91精品免费观看| 久久国产乱子伦免费精品| 久久亚洲国产成人影院网站| 久久精品国产亚洲av影院| 久久青青草原精品国产软件| 久久综合噜噜激激的五月天| 久久精品成人影院| 99久久99久久久精品齐齐| 天天影视色香欲综合久久| 国产午夜久久影院| 亚洲欧美伊人久久综合一区二区 | 精品久久久无码21p发布| 国产精品久久久久久久久免费| 蜜桃麻豆WWW久久囤产精品| 99热成人精品免费久久| 久久九九全国免费| 精品久久久久久无码专区| 久久精品国产2020| 国产精品久久久久久五月尺| 久久免费大片| 久久国产高清一区二区三区| 伊人丁香狠狠色综合久久| 国产午夜久久影院| 久久精品国产精品青草app| 欧美噜噜久久久XXX| 欧洲人妻丰满av无码久久不卡| 精品国产乱码久久久久久呢| 午夜精品久久久内射近拍高清| 国产呻吟久久久久久久92| 精品久久久久久无码免费| 久久精品中文字幕有码| 免费一级欧美大片久久网| 久久久久99这里有精品10|