2
votes

Now I'm involved in a project which needs to download a huge amount of images from server. Following the recommendation online, I tried the ASIHttpRequest. But when I copied all the necessary classes into my project, I got 30+ errors in those classes. Most of the errors are about using retain, release or autorelease. Because I'm using Xcode 4.2.1, explicit retain, release and autorelease is forbidden. But some other errors are quite ridiculous.

for example, in class ASIDataCompressor.m, following method should return NSData

- (NSData *)compressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSError **)err shouldFinish:(BOOL)shouldFinish

but I see one portion of the method return NO

if (status == Z_STREAM_END) {
        break;
    } else if (status != Z_OK) {
        if (err) {
            *err = [[self class] deflateErrorWithCode:status];
        }
        return NO;
    }

Some other classes also have similar problems.

My questions are:

  1. Did I download the wrong package?

  2. How to let compiler ignore those explicit retain, release and autorelease?

2
You didn't download the wrong package, it is just that ASIHTTPRequest hasn't been updated to reflect the changes in XCode 4.2. If you want to use ASI, you will have to tweak your settings a bit (disabling ARC, etc).Logan Serman
Check out AFNetworking instead, I hear it is more current than ASI.Richard J. Ross III

2 Answers

2
votes

"Xcode 4.2.1, explicit retain, release and autorelease is forbidden" because you have ARC enabled when you created your project. Disable ARC.

ASIDataCompressor.m method looks fine here. Don't know how you got it wrong.

Since you just picked up ASIHTTP in your project I would recommend switching to AFNetworking because read this: [request release]

0
votes

As stated above, when using ARC, you cannot use (and no longer need) retain/release/etc.

If you want your overall project to still have ARC, you can disable it for that one file.

When you migrate a project to use ARC, the -fobjc-arc compiler flag is set as the default for all Objective-C source files. You can disable ARC for a specific class using the -fno-objc-arc compiler flag for that class.

In Xcode, go to target Build Phases tab > open the Compile Sources group to reveal the source file list > double-click the file for which you want to set the flag > enter -fno-objc-arc in the pop-up panel, then click Done.