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: about 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 (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-10-19T21:32:02.000Z (9 months ago)
- Last Synced: 2023-11-24T12:35:44.043Z (7 months ago)
- Topics: hacktoberfest, personal-identity-number, personnummer, social-security-number, swift, validation
- Language: Swift
- Homepage:
- Size: 47.9 KB
- Stars: 4
- Watchers: 3
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- 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)
```