0

I'm trying to convert some Apple code (from SquareCam example) to ARC. I had the Apple code flagged to compile as non-ARC and it worked but I was getting crash errors passing images between the non-ARC context to an ARC context - so I'm trying to resolve that.

Anyway, I think I have got all the ARC stuff handled except for this line:

 NSNumber *orientation = CMGetAttachment(imageDataSampleBuffer, kCGImagePropertyOrientation, NULL);

This is used for the CIDetectorImageOrientation key value (CoreImage face detection). I get the ARC error below for this and none of the stuff I have tried resolves this. "imageDataSampleBuffer" is of type CMSampleBufferRef.

What is the correct way to convert the CFTypeRef to the NSNumber I need? - Thanks!

Implicit conversion of a non-Objective-C pointer type 'CFTypeRef' (aka 'const void *') to 'NSNumber *' is disallowed with ARC

spring
  • 18,009
  • 15
  • 80
  • 160

1 Answers1

1

Because you are assigning a CFTypeRef to an NSObject*, the compiler complains. You need to do a __bridge to an NSNumber.

CodaFi
  • 43,043
  • 8
  • 107
  • 153
  • 1
    Thanks! I used `__bridge` since I don't want to transfer ownership and that seems to work. Usually the compiler squawks and offers `__bridge` options but it didn't with the issue I was having. – spring May 03 '12 at 22:13
  • Absolutely! Though, I worry about the retain count of the CF object... If it crashes, use CFRetain() on that CMGetAttachment. – CodaFi May 03 '12 at 22:15
  • `__bridge_transfer` is wrong. The get rule says that the object is not owned by the caller and so he cannot transfer ownership to ARC. – Nikolai Ruhe May 03 '12 at 23:00
  • @CodaFi There's no ownership problem with using `(__bridge NSNumber*)`. Don't just drop `CFRetain` calls without knowing why. – Nikolai Ruhe May 03 '12 at 23:02
  • Wouldn't it be nice if these important details were collected in a wiki rather than being somewhat orphaned in comments. – spring May 03 '12 at 23:29