Skip to content

A swift library to validate and extract information from a string that represents a Swedish Social Security Number.

License

Notifications You must be signed in to change notification settings

diamantidis/SwedishSSN

Repository files navigation

SwedishSSN

CI Status Version License Platform Swift codecov

A swift library to validate and extract information from a string that represents a Swedish Social Security Number.

Requirements

  • iOS 9.3+
  • Xcode 9.3+
  • Swift 4.0+

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate SwedishSSN into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.3'

target 'TargetName' do
    pod 'SwedishSSN'
end

Then, run the following command:

$ pod install

Usage

You can import SwedishSSN into your files

Validate each case with switch

let ssn = "XXXXXX-XXXX"

switch SwedishSSN(ssn) {
case .personnummer(let gender):
    // Do something if it is a valid personnummer
case .samordningsnummer(let gender):
    // Do something if it is a valid samordningsnummer
case .organisationsnummer(let companyType):
    // Do something if it is a valid organisationsnummer
case .invalid:
    // Do something if it is an invalid ssn
}

Validate one specific type with guard case

let ssn = "XXXXXX-XXXX"

guard case SwedishSSN.personnummer(let gender) = SwedishSSN(ssn) else {
    return false
}

Validate one specific type with if case

let ssn = "XXXXXX-XXXX"

if case SwedishSSN.personnummer(let gender) = SwedishSSN(ssn) {
    // Do something if it is a valid personnummer
}

Author

Ioannis Diamantidis, diamantidis@outlook.com

License

SwedishSSN is available under the MIT license. See the LICENSE file for more info.

Acknowledgments

About

A swift library to validate and extract information from a string that represents a Swedish Social Security Number.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published