简体   繁体   English

Xcode中使用目标C的Zlib

[英]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 将此链接用作CDTest.h和CDTest.m,并在我的TestAppDelegate.mi中使用按钮操作调用这些类,如下所示:

-(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. 警告实例方法-gzipData也未在按钮单击上找到:-[CDTest gzipData:]:无法识别的选择器已发送到实例0x7f8d7a009070,因为我是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:

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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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