CPFCNPJTools 2.0.0

CPFCNPJTools 2.0.0

Maintained by Diggo Silva.



  • By
  • Diggo Silva and Helio Mesquita

CPFCNPJTools

iOS LinkedIn: @RodrigoSilva

A iOS application written in Swift, this project is a library for CocoaPods that allows you to validate, generate and manipulate CPF and CNPJ numbers in a simple and efficient way. Ideal for testing and filling out forms.

Difference between CPF and CNPJ

  • CPF (Individual Taxpayer Registry): The CPF is an individual registration number used by the Brazilian Federal Revenue Service to identify an individual. The CPF is made up of 11 digits (XXX.XXX.XXX-XX). It is used for various purposes, such as opening bank accounts, issuing invoices, and filing taxes.

  • CNPJ (National Registry of Legal Entities): The CNPJ is a registration number used by the Brazilian Federal Revenue Service to identify companies or other legal entities. The CNPJ is made up of 14 digits (XX.XXX.XXX/0001-XX). It is used to formalize the existence of a company, allowing it to carry out commercial activities, such as issuing invoices, paying taxes, among others.

Contents

Requirements

  • iOS 17.0 or later
  • Xcode 15.0 or later
  • Swift 5.0 or later

Functionalities

  • CPF Validation: Check if a CPF number is valid, following the rules of the Federal Revenue Service.
  • CNPJ Validation: Check if a CNPJ number is valid, according to tax rules.
  • Fictitious CPF generation: Generate a valid CPF number randomly.
  • Fictitious CNPJ generation: Generate a valid CNPJ number randomly.

Instalation with Cocoapods

Add the dependency to your Podfile:

$ pod 'CPFCNPJTools'

Then run:

$ pod install

Instalation with Swift Package Manager (Xcode 11+)

Swift Package Manager (SwiftPM) is a tool for managing the distribution of Swift code as well as C-family dependency. From Xcode 11, SwiftPM got natively integrated with Xcode.

CPFCNPJTools support SwiftPM from version 5.1.0. To use SwiftPM, you should use Xcode to open your project. Click File -> Add Package Dependencies, enter CPFCNPJTools repo's URL.

HowToUse

1.1 Validate CPF

  • To validate a CPF, simply use the validate(cpf:) method:
let validator = CPFValidator()
let result = validator.validate(cpf: "11144477735")
print(result) // .valid or .invalid

1.2 Generate Fake CPF

  • To generate a fake CPF, simply use the generateFakeCPF() method:
let validator = CPFValidator()
let fakeCPF = validator.generateFakeCPF()
print(fakeCPF) // "11144477735"

1.3 Generate Fake CPF masked

  • To generate a fake CPF with mask, simply use the generateFakeCPFMasked() method:
let validator = CPFValidator()
let fakeCPFMasked = validator.generateFakeCPFMasked()
print(fakeCPFMasked) // "111.444.777-35"

2.1 Validate CNPJ

  • To validate a CNPJ, simply use the validate(cnpj:) method:
let validator = CNPJValidator()
let result = validator.validate(cnpj: "11444777000135")
print(result) // .valid or .invalid

2.2 Generate Fake CNPJ

let validator = CNPJValidator()
let fakeCNPJ = validator.generateFakeCNPJ()
print(fakeCNPJ) // "11444777000135"

2.3 Generate Fake CNPJ masked

let validator = CNPJValidator()
let fakeCNPJMasked = validator.generateFakeCNPJMasked()
print(fakeCNPJMasked) // "11.444.777/0001-35"

Notes:

  • The file is formatted in Markdown (.md), which is the standard for GitHub readme files.
  • The methods are clearly described, with code examples in Swift to show how to use the library.
  • The explanations and comments are all in English, making the documentation accessible to a wider audience.

Feel free to tweak any parts of the documentation to fit your style or add any additional information that you think is important!

If you'd like any more changes or additions, let me know.

Credits

  • Diggo Silva
  • Helio Mesquita