erikberglund / SwiftPrivilegedHelper

Example application using a privileged helper tool with authentication in an unsandboxed application written in Swift
MIT License
180 stars 33 forks source link

Not an issue, a Swift 5 improvement #16

Open stklieme opened 5 years ago

stklieme commented 5 years ago

Thank you for sharing this amazing project. However I'd like to make a suggestion.

Even in Swift 4 it's recommended to prefer Data over NSData but in Swift 5 it became still more comfortable. You can replace the authorizationRef(fromExternalForm method with

 static func authorizationRef(fromExternalForm data: Data) throws -> AuthorizationRef? {

      // Create an AuthorizationExternalForm from it's data representation
      var authRef: AuthorizationRef?
      var authRefExtForm = data.withUnsafeBytes{ $0.load(as: AuthorizationExternalForm.self) }

      // Extract the AuthorizationRef from it's external form
      try executeAuthorizationFunction { AuthorizationCreateFromExternalForm(&authRefExtForm, &authRef) }
      return authRef
 }