According to Apple documentation CFDictionaryRef
and NSDictionary
are Toll-Free Bridged Types
.
However, I get an AV in the following code, which MIGHT be because the bridge does not work with Delphi.
DADiskCopyDescription
returns a CFDictionaryRef
, which I wrap to a NSDictionary
. The pointer is not NIL, but when I access a function in the object, I get an AV:
function osxGetRootVolumeUUID: string;
var lNSDictionary: NSDictionary;
lDisk: DADiskRef;
lCFUrl: CFURLRef;
lSession: DASessionRef;
lUUID: CFUUIDRef;
begin
result := '';
lSession := DASessionCreate(nil);
lCFUrl := TNSURL.OCClass.fileURLWithPath(StrToNSStr('/'));
lDisk := DADiskCreateFromVolumePath(nil,lSession,lCFUrl);
lNSDictionary := TNSDictionary.Wrap(DADiskCopyDescription(lDisk));
lUUID := lNSDictionary.objectForKey(kDADiskDescriptionVolumeUUIDKey); //<- AV here
if lUUID<>nil then
result := CFStringRefToStr( CFUUIDCreateString(nil, lUUID));
lNSDictionary.release;
CFRelease(lCFurl);
end;
I also tried to use CFBridgingRelease
as suggested in this SO question but it gives error SIGABRT (6)
:
lNSDictionary := TNSDictionary.Wrap(CFBridgingRelease(DADiskCopyDescription(lDisk))); //gives error: SIGABRT (6)
How to make it work?
PS. Basically I just want to get the UUID
of the root volume on OSX. The function above is converted to Delphi from an Objective-C function we have used so far.
Edit
Another thing I have tried is to avoid using NSDictionary
, but this gives an error too, which could indicate that the problem is something else:
lCFDictionaryRef := DADiskCopyDescription(lDisk);
lUUID := CFDictionaryGetValue(lCFDictionaryRef, kDADiskDescriptionVolumeUUIDKey); //<- AV here