Functions
The following functions are available globally.
-
Infix operator for testing if a string matches a regular expression.
Example
let sentence = "The world is flat." if sentence =~ "^The" { // The sentence starts with "The" }
Declaration
Swift
public func =~ (input: String, pattern: String) -> Bool
Parameters
input
The string that should be tested.
pattern
The regular expression that should be used for testing.
-
Infix operator for testing if a string matches a regular expression.
Example
let pattern = RegularExpression("^The")! let sentence = "The world is flat." if sentence =~ pattern { // The sentence starts with "The" }
Declaration
Swift
public func =~ (input: String, pattern: RegularExpression) -> Bool
Parameters
input
The string that should be tested.
pattern
The regular expression that should be used for testing.
-
Challenges the user to authenticate as the device owner. Biometric authentication (Face ID or Touch ID) is tried first if available and passcode authentication is used as a fallback.
Examples
var context = authenticateDeviceOwner(reason: "Unlock something") { authenticationError in guard authenticationError == nil else { // Failed to authenticate (the user just might have cancelled) // TODO: Handle error return } // Successfully authenticated unlockSomething() } // Invalidate context context.invalidate()
Note
In order to use Face ID, add [
NSFaceIDUsageDescription
][https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW75] to your [Info.plist
][https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Introduction/Introduction.html#//apple_ref/doc/uid/TP40009248-SW1].Declaration
Swift
public func authenticateDeviceOwner( reason: String, completion: @escaping (_ authenticationError: AuthenticationError?) -> Void ) -> AuthenticationContext
Parameters
reason
The reason describing the purpose of the authentication.
completion
A function that is called after the authentication finished (not neccessarily successfully).
authenticationError
Upon successful authentication this is
nil
else it contains the cause for failure.Return Value
The authentication context.