[非凡程序员]归档 解档 appkit

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {

    @autoreleasepool {

//归档 

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

        NSKeyedArchiver *archiver3 = [[NSKeyedArchiver alloc]initForWritingWithMutableData:data];

        [archiver3 encodeObject:@[@"1",@"2"] forKey:@"num"];

        [archiver3 finishEncoding];

        [data writeToFile:@"/Users/feifanchengxuyuan/Desktop/archiver3.txt" atomically:YES];

//解档

        NSFileManager *filemanager = [NSFileManager defaultManager];

        NSData *fileData = [filemanager contentsAtPath:@"/Users/feifanchengxuyuan/Deskt-p/archiver6.txt"];

        NSKeyedUnarchiver *unArchiver = [[NSKeyedUnarchiver alloc]initForReadingWithData:fileData];

        NSArray *array = [unArchiver decodeObjectForKey:@"num"];

        NSLog(@"%@ %@",array[0],array[1]);

    }

    return 0;

}

@interface ViewController : NSViewController

@property (weak) IBOutlet NSTextField *input;

@property (weak) IBOutlet NSTextField *output;

- (IBAction)upper:(id)sender;

- (IBAction)lower:(id)sender;


#import "ViewController.h"


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];


    [_input setStringValue:@"haoba"];

}


- (void)setRepresentedObject:(id)representedObject {

    [super setRepresentedObject:representedObject];


    // Update the view, if already loaded.

}


- (IBAction)upper:(id)sender {

    NSString *in = [_input stringValue];

    NSString *change = [in uppercaseString];

    [_output setStringValue:change];

}


- (IBAction)lower:(id)sender {

    NSString *in =[_input stringValue];

    NSString *change = [in lowercaseString];

    [_output setStringValue:change];

}

@end


你可能感兴趣的:([非凡程序员]归档 解档 appkit)