Here’s a quick-start iOS security example that covers secure token storage, biometric unlock, and protected file writes: ```swift import Foundation import LocalAuthentication import Security enum SecureStore { static func saveToken(_ token: String, account: String = "authToken") throws { let data = Data(token.utf8) let query: [String: Any] = [ kSecClass as String: kSecClassGenericPassword, kSecAttrAccount as String: account, kSecValueData as String: data ] SecItemDelete(query as CFDictionary)...
Scanned 9/5/2026
Install to Claude Code
npx -y skills add HoangNguyen0403/agent-skills-standard --skill ios-security --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Ios Security?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-ios-security-313131d1)More formats (shields.io, HTML) on the badges page.
Here’s a quick-start iOS security example that covers secure token storage, biometric unlock, and protected file writes:
```swift
import Foundation
import LocalAuthentication
import Security
enum SecureStore {
static func saveToken(_ token: String, account: String = "authToken") throws {
let data = Data(token.utf8)
let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrAccount as String: account,
kSecValueData as String: data
]
SecItemDelete(query as CFDictionary)
let status = SecItemAdd(query as CFDictionary, nil)
guard status == errSecSuccess else {
throw NSError(domain: NSOSStatusErrorDomain, code: Int(status))
}
}
static func readToken(account: String = "authToken") throws -> String {
let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrAccount as String: account,
kSecReturnData as String: true,
kSecMatchLimit as String: kSecMatchLimitOne
]
var item: CFTypeRef?
let status = SecItemCopyMatching(query as CFDictionary, &item)
guard status == errSecSuccess,
let data = item as? Data,
let token = String(data: data, encoding: .utf8) else {
throw NSError(domain: NSOSStatusErrorDomain, code: Int(status))
}
return token
}
}
func authenticateUser(completion: @escaping (Bool) -> Void) {
let context = LAContext()
var error: NSError?
guard context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) else {
completion(false)
return
}
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics,
localizedReason: "Unlock your secure session") { success, authError in
if let laError = authError as? LAError {
switch laError.code {
case .userCancel, .authenticationFailed:
completion(false)
default:
completion(false)
}
return
}
completion(success)
}
}
func saveProtectedFile(_ data: Data, to url: URL) throws {
try data.write(to: url, options: .completeFileProtection)
}
```
Use this as the baseline:
- Store tokens and PII in Keychain with `SecItemAdd` / `SecItemCopyMatching`, not `UserDefaults`
- Gate sensitive actions with `LAContext` and check `canEvaluatePolicy` first
- Write sensitive files with `.completeFileProtection`
- Keep App Transport Security enabled
- Avoid logging tokens or PII in release builds
- Add certificate pinning for production network traffic
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!