Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this NSErrorPointer type?

  1. 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?

  2. 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?

  3. But why is then Swift converting &error to NSErrorPointer, is that autoboxed?

    var errorPtr: NSErrorPointer = &error

  4. 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)

like image 824
Binarian Avatar asked Dec 09 '22 07:12

Binarian


1 Answers

Solution to 4. I found out how to dereference it:

var error: NSError = errorPtr.memory!
like image 85
Binarian Avatar answered Dec 11 '22 08:12

Binarian