Type mismatch in SessionGetInfo() swift

The Apple documentation for SessionGetInfo for swift mentions that this API takes third argument of type UnsafeMutablePointer<SessionAttributeBits>? but I m getting the below error when I pass an argument of this type.

Cannot convert value of type 'UnsafeMutablePointer<SessionAttributeBits>' to expected argument type 'UnsafeMutablePointer<UInt32>'

Why is it expecting a different type. The documentation states otherwise. How to resolve this? Is this a Bug?

 public static func GetSessionInfo () -> Void
    {
        var sessionID = SecuritySessionId()
        var sessionAttrs = SessionAttributeBits()
        
        let status = SessionGetInfo(callerSecuritySession,
                                    &sessionID,
                                    &sessionAttrs) //error:Cannot convert value of type 'UnsafeMutablePointer<SessionAttributeBits>' to expected argument type 'UnsafeMutablePointer<UInt32>'
        
        if status != errSessionSuccess {
            print("Could not get session info. Error \(status)")
        } 
    }

I put the following code into a new command-line tool project

import Security

func main() {
    var sessionID = SecuritySessionId()
    var sessionAttrs = SessionAttributeBits()
    let err = SessionGetInfo(callerSecuritySession, &sessionID, &sessionAttrs)
    if err == errSecSuccess {
        print(sessionID)
        print(sessionAttrs)
    }
}

main()

It builds and runs on my machine, printing:

100012
SessionAttributeBits(rawValue: 24624)

What Xcode version are you using?

I’m using 15.2.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I m also using Xcode 15.2, but I m still getting this error. I am having a macOS GUI project.

I am having a macOS GUI project.

Have you tried it with a new test project? I suspect there’s something specific about your main project that’s causing this problem.

Please do this:

  1. In Xcode 15.2, chose File > New > New Project.

  2. Then chose macOS > App, with Storyboard for the UI.

  3. Add the code above to applicationDidFinishLaunching(_:).

  4. Compile and run the app.

When I did this the app compiled and ran just fine, printing similar results to what I got above.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I have tried this in an independent project and it works. However, I have figured out the reason why I m getting this error and wanted your help on how to resolve this.

My project is using the new interop mechanism using the modulemap file. For this, I m setting the interoperability to c++ in the build setting. After changing the interoperability to C++, I m getting this error for the SessionGetinfo Api. Can you please check this?

 public static func GetSessionInfo () -> Void
    {
        var sessionID = SecuritySessionId()
        var sessionAttrs = SessionAttributeBits()
        
        let status = SessionGetInfo(callerSecuritySession,
                                    &sessionID,
                                    &sessionAttrs) //error:Cannot convert value of type 'UnsafeMutablePointer<SessionAttributeBits>' to expected argument type 'UnsafeMutablePointer<UInt32>'
        
        if status != errSessionSuccess {
            print("Could not get session info. Error \(status)")
        } 
    }

You can try this in your project.

@eskimo Can you please revert on this?

Can you please revert on this?

Please read tip 3 in Quinn’s Top Ten DevForums Tips.

After changing the interoperability to C++, I m getting this error for the SessionGetinfo API.

OK, interesting. You should definitely file a bug about that.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Type mismatch in SessionGetInfo() swift
 
 
Q