Swift: How to get Console User, UID, and GID via SCDynamicStoreCopyConsoleUser?
Question: I am able to get the Username, UID and GID from SCDynamicStoreCopyConsoleUser
using python:

    
    
     #!/usr/bin/python
     from SystemConfiguration import SCDynamicStoreCopyConsoleUser
     cfuser = SCDynamicStoreCopyConsoleUser( None, None, None )
     print cfuser[0] # Returns console user, e.g.: myUsername
     print cfuser[1] # Returns console user’s UID, e.g.: 501
     print cfuser[2] # Returns console user’s GID, e.g.: 20
    

How can I get this same return using Swift?

Swift Declaration of SCDynamicStoreCopyConsoleUser

    
    
     func SCDynamicStoreCopyConsoleUser(_ store: SCDynamicStore!,
                                        _ uid: CMutablePointer<uid_t>,
                                        _ gid: CMutablePointer<gid_t>) -> Unmanaged<CFString>!
    

My Swift Call

    
    
     var uid: CMutablePointer<uid_t>!
     var gid: CMutablePointer<gid_t>!
    
     var cfuser: NSArray = [SCDynamicStoreCopyConsoleUser(nil,uid,gid)]
    
     // the return has only one element containing the username
    


Answer: The Swift function `SCDynamicStoreCopyConsoleUser` takes a
`CMutablePointer<uid_t>` argument which means that you have to pass the
_address_ of a `uid_t` variable. Also you should check if the call succeeded
(otherwise `nil` is returned), and you have to convert the returned unmanaged
object as described in [Working with Cocoa Data
Types](https://developer.apple.com/library/prerelease/mac/documentation/Swift/Conceptual/BuildingCocoaApps/WorkingWithCocoaDataTypes.html):

    
    
    import SystemConfiguration
    
    var uid: uid_t = 0
    var gid: gid_t = 0
    
    if let theResult = SCDynamicStoreCopyConsoleUser(nil, &uid, &gid) {
        let name = theResult.takeUnretainedValue()
        println("name = \(name), uid = \(uid), gid = \(gid)")
    } else {
        println("failed")
    }
    

