Code Monkey home page Code Monkey logo

swiftrandom's Introduction

SwiftRandom

Carthage compatible CocoaPods Compatible

SwiftRandom is a tiny help suite for generating random data such as

  • Random human stuff like: names, gender, titles, tags, conversations
  • Random data types like: Int, CGFloat, Bool, UIColor, NSDate, NSURL, element in Array

Usage

func asExtension() {
	Int.random(2, 77) // Random between 2-77
	Int.random(2...77)
	Int32.random(13, 37) // Random between 13-37
	Int32.random(13...37)
	Double.random()
	Float.random(3.2, 4.5) // Random between 3.2-4.5
	CGFloat.random()
	NSDate.random()
	NSDate.randomWithinDaysBeforeToday(7)
	UIColor.random()
	NSURL.random()
	
	// Array Extensions
	var someArray = ["hello", "world"]
	someArray[0..<someArray.count].randomItem() // Array slice
	someArray.randomItem()
}
func asMethods() {
	// Return random Int >= 10 and <= 20
	// Example Output: 13
	Randoms.randomInt(10,20)
	
	// Return random Int32 >= 10 and <= 20
	// Example Output: 13
	Randoms.randomInt32(10,20)
	
	// Return random Double >= 10 and <= 20
	// Example Output: 11.511219042938
	Randoms.randomDouble(10,20)

	// Return random Float >= 10 and <= 20
	// Example Output: 17.0361
	Randoms.randomFloat(10,20)

	// Return random CGFloat between 1 >= and >= 0
	// Example Output: 0.622616
	Randoms.randomCGFloat()

	// Return true 30%, false %70
	// Example Output: false
	Randoms.randomPercentageisOver(70)

	// Return true or false
	// Example Output: false
	Randoms.randomBool()

	// Return random NSDate today > and > today - 7.
	// Example Output: 2015-10-08 03:55:09 +0000
	Randoms.randomDateWithinDaysBeforeToday(7)

	// Random Date since 1970
	// Example Output: 1997-02-01 15:27:08 +0000
	Randoms.randomDate()

	// Return UIColor. Alpha channel always 1.
	// Example Output: UIDeviceRGBColorSpace 0.645737 0.126625 0.52535 1
	Randoms.randomColor()

	// Return random NSURL
	// Example Output: http://leagueoflegends.com/
	Randoms.randomNSURL()

	// ==================== Fake Generators for Fake Datasources ==================== //

	// Return random name
	// Example Output: "Megan Freeman"
	Randoms.randomFakeName()

	// Return random fake name prefixed by English honorific
	// Example Output: "Dr. Megan Freeman"
	Randoms.randomFakeNameAndEnglishHonorific()

	// Return "Male" or "Female" as String
	// Example Output: "Female"
	Randoms.randomFakeGender()

	// Return random conversation
	// Example Output: "No! I'm tired of doing what you say."
	Randoms.randomFakeConversation()

	// Return random title
	// Example Output: "B2 Pilot @ USAF"
	Randoms.randomFakeTitle()

	// Return random tag as string
	// Example Output: "question"
	Randoms.randomFakeTag()
	
	// Return random currency as String
	// Example Output: "EUR"
	Randoms.randomCurrency()
	
	// Return random (non-existing) gravatar as UIImage?
	// The image is optional in case of network issues
	Randoms.randomGravatar { (image, error) -> Void in
		// Handle the image/error
	}
	
	// For consistance behaviour you can create custom Gravatar
	Randoms.createGravatar(Randoms.GravatarStyle.Retro) { (image, error) -> Void in
		// Handle the image/error
	}
}

###Requirements

  • Swift version 2.0

Installation

Install via Carthage

  • Create a Cartfile with the following specification and run carthage update.
github "thellimist/SwiftRandom" >= 0.1.7
  • Follow the instructions to add the framework to an iOS project.

Install via CocoaPods

You can use CocoaPods to install SwiftRandom by adding it to your Podfile:

platform :ios, '8.0'
use_frameworks!

pod  'SwiftRandom'

Install Manually

  • Download and drop 'Randoms.swift' in your project.

###Improvement

  • Feel free adding your own random data functions and sending pull requests.

#####Possible features:

  • Random wildlife pictures (Should not include the image inside project, should load it from web when needed)
  • Make OSX compatiable and add here: https://github.com/AndrewSB/awesome-osx
  • Random JSON
  • Random Gifs (Should not include gifs inside the project, should load it from web when needed)
  • Random Videos (Should not include videos inside the project, should load it from web when needed)
  • Implement SwiftRandom as a protocol any class can conform to (Post.random() would give you a random post)

###License

  • SwiftRandom is available under the MIT license. See the LICENSE file.

##Keywords random, swift, data, generator, faker, fake, gravatar

swiftrandom's People

Contributors

thellimist avatar esqarrouth avatar krider2010 avatar bcylin avatar ollie-eman avatar vdka avatar sabatinomasala avatar andrewsb avatar demiculus avatar felipeferri avatar wohlert avatar kellyi avatar lufzi avatar readmecritic avatar

Watchers

James Cloos avatar  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.