This is a Swift port of the awesome PHP Faker library with more Swift specific code (not a direct port).
- iOS 8.0+
CocoaPods is a dependency manager for Cocoa projects.
CocoaPods 0.36 adds supports for Swift and embedded frameworks. You can install it with the following command:
$ gem install cocoapods
To integrate Faker into your Xcode project using CocoaPods, specify it in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'Faker'
Then, run the following command:
$ pod install
When using Faker, it has a very small set of data without configuration.
You can configure Faker to use specific locales by calling the
Faker.Configuration.localize()
method:
use Faker
Faker.Configuration.localize()
// OR
Faker.Configuration.localize(NSLocale(localeIdentifier: "en_US"))
The Uuid
generator can be used to generate random UUID strings:
use Faker
Faker.Uuid.uuid()
The Person
generator can be used to generate identity information:
use Faker
Faker.Person.name()
Faker.Person.name(.Male)
Faker.Person.name(.Female)
Faker.Person.firstName()
Faker.Person.firstName(.Male)
Faker.Person.firstName(.Female)
Faker.Person.lastName()
Faker.Person.title()
Faker.Person.title(.Male)
Faker.Person.title(.Female)
Faker.Person.maleTitle()
Faker.Person.maleFirstName()
Faker.Person.femaleTitle()
Faker.Person.femaleFirstName()
The Lorem
generator can be used to generate random text:
use Faker
let word : String = Faker.Lorem.word()
let words : String = Faker.Lorem.words()
let words : [String] = Faker.Lorem.words()
let sentence : String = Faker.Lorem.sentence()
let sentences : String = Faker.Lorem.sentences()
let sentences : [String] = Faker.Lorem.sentences()
let paragraph : String = Faker.Lorem.paragraph()
let paragraphs : String = Faker.Lorem.paragraphs()
let paragraphs : [String] = Faker.Lorem.paragraphs()
let text : String = Faker.Lorem.text()
The Company
generator can be used to generate company information:
use Faker
Faker.Company.company()
Faker.Company.companySuffix()
The Internet
generator can be used to generate internet data:
use Faker
Faker.Internet.email()
Faker.Internet.safeEmail()
Faker.Internet.freeEmail()
Faker.Internet.companyEmail()
Faker.Internet.url()
Faker.Internet.tld()
Faker.Internet.slug()
Faker.Internet.domainWord()
Faker.Internet.domainName()
Faker.Internet.freeEmailDomain()
Faker.Internet.safeEmailDomain()
Faker.Internet.username()
Faker.Internet.password()
Faker.Internet.ipv4()
Faker.Internet.ipv6()
Faker.Internet.localIpv4()
Faker.Internet.mac()
use Faker
Int.random() // 291651651
Int.random(1, max: 6) // 4
Int.number() // 3
Int.number(5) // 41532
100.randomize(40) // 110
use Faker
Double.random() // 1979448.82734655
Double.random(3, min: 10, max: 20) // 15.166
4.321231.decimals(2) // 4.32
use Faker
"Lorem ipsum".shuffle() // mLismore pu
"### %%%".numerify() // 031 452
"??? ***".lexify() // ogv ]oM
"foo bar baz".split(" ") // [ "foo", "bar", "baz" ]
use Faker
["foo", "bar", "baz"].shuffle() // In-place shuffle
["foo", "bar", "baz"].shuffled() // Non-mutating method
["foo", "bar", "baz"].random() // Random element from array
["foo", "bar", "baz"].random(2) // Multiple random elements from array
use Faker
Character.randomLetter() // a
Character.randomAscii() // 3
use Faker
NSDate.random()
NSDate.random(NSDate().timeIntervalSince1970, max: NSDate().timeIntervalSince1970 + 3600)
use Faker
UIColor.random() // Normal alpha level
UIColor.random(0.5) // Custom alpha level
use Faker
UIImage.random()
UIImage.random(1920, width: 1080, category: .People)
UIImage.avatar()
UIImage.avatar("[email protected]")
UIImage.avatar("[email protected]", size: 80)