Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/personnummer/swift
Validate Swedish personal identity numbers
https://github.com/personnummer/swift
hacktoberfest personal-identity-number personnummer social-security-number swift validation
Last synced: 2 months ago
JSON representation
Validate Swedish personal identity numbers
- Host: GitHub
- URL: https://github.com/personnummer/swift
- Owner: personnummer
- License: mit
- Created: 2018-01-08T07:52:35.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-05-20T20:58:57.000Z (8 months ago)
- Last Synced: 2024-05-29T23:36:06.898Z (8 months ago)
- Topics: hacktoberfest, personal-identity-number, personnummer, social-security-number, swift, validation
- Language: Swift
- Homepage:
- Size: 50.8 KB
- Stars: 4
- Watchers: 4
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-sweden - Swift
README
# Personnummer [![Build Status](https://github.com/personnummer/swift/workflows/build/badge.svg)](https://github.com/personnummer/swift/actions)
Small library to validate and format swedish personal identity numbers called "Personnummer".
## Installation
### Cocoapods
```ruby
pod 'Personnummer', '~> 1.0.0'
```### Swift Package Manager
```swift
.package(url: "https://github.com/personnummer/swift.git", from: "1.0.2")
```## Usage
```swift
// Validate
if !Personnummer.isValid(personnummerString) {
fatalError("Personnummer \(personnummerString) was invalid")
}// Validate and format
if let formattedPersonnummer = Personnummer.format(personnummerString) {
print(formattedPersonnummer)
}// Get components of valid personnummer such as year etc and format
guard let personnummer = Personnummer(personnummer: personnummerString) {
fatalError("Personnummer \(personnummerString) was invalid")
}print(personnummer.century)
print(personnummer.year)
print(personnummer.month)
print(personnummer.day)
print(personnummer.separator)
print(personnummer.fourLast)
```