Search code examples
objective-cmemoryautomatic-ref-countingqr-coderetain

Converting 'ZXingObjC' (QR Code Library) non-ARC to ARC, have some problems


I've never worked with non-ARC before, and I tried ZXingObjC sample project (QR Code Scanner), it's non-ARC project as well as the library. I started with deleting the autorealese, dealloc etc. But I've encounter 'retain' and I don't know yet how to handle it. I'll glad for a hand as it will benefit a lot of us.

Example of 'retain' statements:

if (zxd) {
    input =
      [ZXCaptureDeviceInput deviceInputWithDevice:zxd
                                       ZXAV(error:nil)];
    [input retain];
  }

Another One:

- (void)setCaptureDevice:(ZXCaptureDevice *)device {
  if (device == capture_device) {
    return;
  }

  if(capture_device) {
    ZXQT({
      if ([capture_device isOpen]) {
        [capture_device close];
      }});
    [capture_device release];
  }

  capture_device = [device retain];
}

EDIT: OK, I've been trying to make "EDIT --> Refactor --> Convert to Objective-C ARC", I get: enter image description here


Solution

  • OK, what I did is:

    1. Clean all non-ARC old code.
    2. "EDIT --> Refactor --> Convert to Objective-C ARC".
    3. Added missing AudioToolbox.Framework

    Project now fully work with ARC. I'll upload later to github.