• <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>

            大龍的博客

            常用鏈接

            統(tǒng)計

            最新評論

            copyWithZone --- 轉(zhuǎn)

            iphone歸檔

              歸檔指的是另一種型式的序列化,但它是任保對象都可以實現(xiàn)的更常規(guī)的類型。
             
              其作用為:進行數(shù)據(jù)的持久化保存。
             
              對象必須實現(xiàn)NSCodeing協(xié)議和NSCopying協(xié)議。
             
            @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"];
            }
             
             
            對數(shù)據(jù)進行歸檔
             
            FourLines *fourLines = [[FourLines alloc] init];
                fourLines.field1 = field1.text;
                fourLines.field2 = field2.text;
                fourLines.field3 = field3.text;
                fourLines.field4 = field4.text;
               
            //對數(shù)據(jù)進行歸檔
                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];   
             
             
             
            獲取歸檔數(shù)據(jù)
             
                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 大龍 閱讀(1268) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            久久99精品久久久久久动态图| 亚洲婷婷国产精品电影人久久| 久久亚洲美女精品国产精品| 日产精品久久久久久久性色 | 国产午夜精品久久久久免费视 | 久久精品国产精品亜洲毛片| 亚洲一级Av无码毛片久久精品| 东方aⅴ免费观看久久av| 久久久久亚洲AV成人片| 久久综合五月丁香久久激情| 亚洲AV无码久久精品色欲| 久久精品无码av| 久久精品亚洲中文字幕无码麻豆| 91久久精品电影| 无码精品久久久天天影视| 久久丝袜精品中文字幕| 精品国产91久久久久久久| 一本色道久久88综合日韩精品 | 2021最新久久久视精品爱| 久久香蕉国产线看观看99| 久久精品国产99久久久古代 | 亚洲精品国精品久久99热一| 久久影视综合亚洲| 国产精品美女久久久久av爽| 久久超碰97人人做人人爱| 久久久久久曰本AV免费免费| 亚洲午夜精品久久久久久app| 国产亚州精品女人久久久久久 | 免费久久人人爽人人爽av| 久久夜色精品国产| 久久久无码精品亚洲日韩软件| 狠狠干狠狠久久| 97热久久免费频精品99| 日韩精品久久久肉伦网站| 久久香综合精品久久伊人| 2021国内精品久久久久久影院| 日本亚洲色大成网站WWW久久 | 亚洲欧美日韩久久精品 | 人妻精品久久久久中文字幕69| 久久人人添人人爽添人人片牛牛| 久久免费视频1|