I have two ODRecord objects in Swift, and am trying to see if one is a member of the other. I tried:
func myIsMember_attempt1(_ r: ODRecord, ofGroup g: ODRecord) -> Bool? {
do {
let isM = try g.isMemberRecord(r)
// -> Constant 'isM' inferred to have type '()', which may be unexpected
return isM;
} catch {
print("Error: \(error)")
return nil;
}
}
Despite the discussion of "Return value" at https://developer.apple.com/documentation/opendirectory/odrecord/1427975-ismemberrecord it appears the ODRecord.isMemberRecord()
function does not return any value!? [I'm guessing due to the idiosyncratic implementation of the underlying BOOL-returning NSError-taking method on the Objective-C side?]
So noticing there was also a ODRecordContainsMember
function available, I tried:
func myIsMember_attempt2(_ r: ODRecord, ofGroup g: ODRecord) -> Bool? {
let isM = ODRecordContainsMember(
Unmanaged.passUnretained(g).toOpaque() as! ODRecordRef,
Unmanaged.passUnretained(r).toOpaque() as! ODRecordRef,
nil
)
// -> Treating a forced downcast to 'ODRecordRef' as optional will never produce 'nil' [??https://bugs.swift.org/browse/SR-4209]
// -> crashes when run…!
return isM;
}
so it seems that an ODRecordRef
isn't just the raw pointer of an ODRecord
?
Is there any chance of the ODRecord.isMemberRecord()
method getting fixed in Swift? Is there any way to use ODRecordContainsMember
from Swift in the meantime?