In Swift the ampersand sign &
is for inout
parameters. Like
var value = 3
func inoutfunc(inout onlyPara: Int) {
onlyPara++
}
inoutfunc(&value) // value is now 4
That doesn't look like onlyPara
is a pointer, maybe it is and get dereferences immediately when using it inside the function.
Is onlyPara a pointer?
When I don't need a IntPointer
type, why are the framework methods using a NSErrorPointer
type? Because they can't change the methods because of existing Objective-C code?
But why is then Swift converting &error
to NSErrorPointer
, is that autoboxed?
var errorPtr: NSErrorPointer = &error
And when I have a NSErrorPointer
. How do I dereference it?
var error: NSError = *errorPtr // won't work
Maybe someone can enlighten me. Using only Swift is easy. I think the questions are one chunk of knowledge over &
between swift and Objective-C (as the address of operator)
Solution to 4. I found out how to dereference it:
var error: NSError = errorPtr.memory!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With