What is this type of NSErrorPointer?

  • In Swift, the ampersand sign &is for parameters inout. how

    Value var = 3

    func inoutfunc (inout onlyPara: Int) {

    onlyPara ++

    }

    inoutfunc (& value) // value is now 4

    It doesn’t look like it onlyParais a pointer, it is possible that it exists and gets played immediately when using it inside a function. Is only a Para a pointer?

  • When I do not need the type IntPointer, why the structure type methods use NSErrorPointer? . Because they cannot change methods due to existing Objective-C code?

  • But why then does Swift convert &errortoNSErrorPointer , is it autoboxed?

    var errorPtr: NSErrorPointer = & error

  • NSErrorPointer. ?

    var: NSError = * errorPtr//


- . Swift . , - & Objective-C ( )

+4
3

"" " Swift" Cocoa Objective-C: https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html#//apple_ref/doc/uid/TP40014216-CH8-XID_16

"" , , Swift. , NSError AutoreleasingUnsafePointer<NSError>. NSErrorPointer :

typealias NSErrorPointer = AutoreleasingUnsafePointer<NSError?>

? NSError? , NSError nil.

, !

+5

4. , :

var error: NSError = errorPtr.memory!
+7

Swift 3

var errorPtr: NSErrorPointer = nil
callSomeFunctionThatReceivesParamByReference(.., error: errorPtr)
if let error = errorPtr?.pointee { ... }
+2
source

Source: https://habr.com/ru/post/1546262/


All Articles