简体   繁体   中英

Zlib in Xcode using objective c

I am using this link as my CDTest.h and CDTest.m and in my TestAppDelegate.mi am calling these class with button action as

-(IBAction)Zipbtn:(id)sender{

    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSLog(@"paths=%@",paths);
    NSString* dPath = [paths objectAtIndex:0];
    NSLog(@"dpaths=%@",dPath);

    NSString* txtfile = [dPath stringByAppendingPathComponent:@"test.txt"];
    NSLog(@"txtfile=%@",txtfile);

    NSData* data=[txtfile dataUsingEncoding:NSUTF8StringEncoding];
     NSLog(@"data=%@",data);

   CDTest *obj=[[CDTest alloc]init];
    [obj gzipData:data];


}

but showing

warning instance method -gzipData not found also on button click shows :-[CDTest gzipData:]: unrecognized selector sent to instance 0x7f8d7a009070 Please help me out as i am new to Mac osx.

The method is a class method - not an instance method. You should be using:

[CDTest gzipData:data]

Additionally, you're actually creating an NSData from the string when you do:

NSData* data=[txtfile dataUsingEncoding:NSUTF8StringEncoding];

What you want to do is get the data from the content of the file, which is:

NSData *data = [NSData dataWithContentsOfFile:txtfile];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM