Giter VIP home page Giter VIP logo

faker's Introduction

Faker

Carthage compatible

This is a Swift port of the awesome PHP Faker library with more Swift specific code (not a direct port).

Requirements

  • iOS 8.0+

Installation

CocoaPods

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

Usage

Generators

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"))

Uuid

The Uuid generator can be used to generate random UUID strings:

use Faker

Faker.Uuid.uuid()

Person

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()

Lorem

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()

Company

The Company generator can be used to generate company information:

use Faker

Faker.Company.company()
Faker.Company.companySuffix()

Internet

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()

Extensions

Foundation

Int
use Faker

Int.random()            // 291651651
Int.random(1, max: 6)   // 4

Int.number()            // 3
Int.number(5)           // 41532

100.randomize(40)       // 110
Double
use Faker

Double.random()                     // 1979448.82734655
Double.random(3, min: 10, max: 20)  // 15.166

4.321231.decimals(2)                // 4.32
String
use Faker

"Lorem ipsum".shuffle()             // mLismore pu
"### %%%".numerify()                // 031 452
"??? ***".lexify()                  // ogv ]oM
"foo bar baz".split(" ")            // [ "foo", "bar", "baz" ]
Array
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
Character
use Faker

Character.randomLetter()            // a
Character.randomAscii()             // 3
NSDate
use Faker

NSDate.random()
NSDate.random(NSDate().timeIntervalSince1970, max: NSDate().timeIntervalSince1970 + 3600)

UIKit

UIColor
use Faker

UIColor.random()        // Normal alpha level
UIColor.random(0.5)     // Custom alpha level
UIImage
use Faker

UIImage.random()
UIImage.random(1920, width: 1080, category: .People)

UIImage.avatar()
UIImage.avatar("[email protected]")
UIImage.avatar("[email protected]", size: 80)

faker's People

Contributors

kleiram avatar ksylvest avatar robgrant avatar tflhyl avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.