// CFArrayToArray converts a CFArrayRef to an array of CFTypes. func CFArrayToArray(cfArray C.CFArrayRef) (a []C.CFTypeRef) { count := C.CFArrayGetCount(cfArray) if count > 0 { a = make([]C.CFTypeRef, count) C.CFArrayGetValues(cfArray, C.CFRange{0, count}, (*unsafe.Pointer)(&a[0])) } return }
func convertCFArrayToSliceHelper(cfArray C.CFArrayRef, helper func(elem cfTypeRef, idx, count int) (bool, error)) error { count := C.CFArrayGetCount(cfArray) if count == 0 { return nil } cfTypes := make([]cfTypeRef, int(count)) cfRange := C.CFRange{0, count} C.CFArrayGetValues(cfArray, cfRange, (*unsafe.Pointer)(&cfTypes[0])) for i, cfObj := range cfTypes { keepGoing, err := helper(cfObj, i, int(count)) if err != nil { return err } if !keepGoing { break } } return nil }