0

When perform a migration of my project to Obejctive-C ARC, i got one error:

implicit conversion of 'bool' (aka 'signed char') to 'nsdata *' is disallowed with arc

The function Xcode is referring to for this error is returning NO or nil although its returning type is of type NSData:

 - (NSData *)compressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSError **)err shouldFinish:(BOOL)shouldFinish
    {
        if (length == 0) return nil;
        int status;
            if (status == myVariable) {
            break;
        } else if (status != y_OK) {
        if (err) {
            *err = [[self class] deflateErrorWithCode:status];
        }
        return NO;
    }

However, i am not quite sure i know how to fix that, any idea will be appreciated.

Luca
  • 20,399
  • 18
  • 49
  • 70

2 Answers2

2

Under ARC you are only allowed to return an object or nil. Period.

This is because ARC not just requires, but DEMANDS that you don't do anything fishy with pointers - that pointers either point to objects or nil.

ARC is having fits because you are trying to stuff NO (a zero value) into a pointer. This violates the rules and that is why you are getting an error.

We can't help you fix it because a) we don't know what the valid return values are for (why NO? Why not nil?). Since this appears to be a code fragment, it is hard to help you. Sorry.

Feloneous Cat
  • 895
  • 1
  • 8
  • 15
0

Just don't do that. NO is not in any sense a valid return value for that function. Your code was broken before ARC, and now it's still broken after.

Also, these lines:

  int status;
  if (status == myVariable) {
        break;
  }

are exactly the same as these:

if (myVariable == nil) {
    break;
}

except written in a really confusing way, and relying on ARC to initialize status. I'm pretty sure that's not what you wanted.

Basically, this method looks completely wrong.

Catfish_Man
  • 41,261
  • 11
  • 67
  • 84