cocoaiokitdiskarbitration

Cocoa get disk in NSArray


hi I'm using DiskArbitration.framework to get list of disks

+(NSArray*)arrayOfDisks {
    DASessionRef session = DASessionCreate(kCFAllocatorDefault);
    if (session) {
        DARegisterDiskAppearedCallback(session, NULL, driveGo, NULL);
        DASessionScheduleWithRunLoop(session,
                                     CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
        CFRelease(session);
    }
    return nil;
}

void driveGo(DADiskRef disk, void *context) {
    NSLog(@"%s", DADiskGetBSDName(disk));
}

it logs up just fine, but how can I return array back? it just loop so I even dont know how to check is it done or not.


Solution

  • You could change your method and store the array in a private variable:

    (void*) driveGo(DADiskRef disk, void *context) {
    NSLog(@"%s", DADiskGetBSDName(disk));
    self->_myArray = DADiskGetBSDName(disk);
    

    }