Skip to content

Instantly share code, notes, and snippets.

func setPassword(serivce: String, account: String, password: Data) {
// 1. the query dictionary
let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrService as String: service,
kSecAttrAccount as String: account,
kSecValueData as String: password
]
// 2. The function that actually store the value
func delete(service: String, account: String) throws {
// 1. create the query dictionary
let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrService as String: service,
kSecAttrAccount as String: account
]
// 2. delete the item
let result = SecItemDelete(query as CFDictionary)
func update(service: String, account: String, password: Data) {
let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrService as String: service,
kSecAttrAccount as String: account
kSecValueData as String: password,
]
let status = SecItemUpdate(query as CFDictionary, nil)
func get(service: String, account: String) -> Data? {
// 1. create the query dictionary
let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrService as String: service,
kSecAttrAccount as String: account,
kSecReturnData as String: true
]
// 2. create a variable to hold the result of the query
func update(service: String, account: String, type: Int, password: Data) {
let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrService as String: service,
kSecAttrAccount as String: account
kSecValueData as String: password,
kSecAttrType as String: type
]
let status = SecItemUpdate(query as CFDictionary, nil)
func update(service: String, account: String, label: String, password: Data) {
let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrService as String: service,
kSecAttrAccount as String: account
kSecValueData as String: password,
kSecAttrLabel as String: label
]
let status = SecItemUpdate(query as CFDictionary, nil)
func createQuery(for serivce: String) -> [String: Any] {
let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrService as String: service,
kSecReturnData as String: true,
kSecMatchLimit as String: kSecMatchLimitAll
]
return query
}
extension CFArray {
var toSwiftArray: [Data] {
let array = Array<AnyObject>(_immutableCocoaArray: self)
return array.compactMap { $0 as? Data}
}
}
func createQuery(for serivce: String) -> [String: Any] {
let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrService as String: service,
kSecReturnAttributes as String: true,
kSecReturnData as String: true,
kSecMatchLimit as String: kSecMatchLimitAll
]
return query
}
@cipolleschi
cipolleschi / FlowCoordinator.swift
Last active May 11, 2020 08:48
Alternative to the waitForState that do not keep a thread busy and has the same sematic.
// Main Logic
struct ShowExposureNotification {
func sideEffect() {
// navigate
Utils.Show(
"Screen.onboardingStep",
context: "exposureNotificationPermissions"
)