Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 3 #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Faker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,12 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = Apostle;
TargetAttributes = {
F6C07BCF1B820BD2004E8BDD = {
CreatedOnToolsVersion = 6.4;
LastSwiftMigration = 0800;
};
F6C07BDA1B820BD2004E8BDD = {
CreatedOnToolsVersion = 6.4;
Expand Down Expand Up @@ -389,8 +390,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -438,8 +441,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -459,6 +464,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.4;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -470,6 +476,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -482,13 +489,15 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
F6C07BE81B820BD2004E8BDD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -500,6 +509,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "nl.apostle.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion Faker.xcodeproj/xcshareddata/xcschemes/Faker.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
12 changes: 6 additions & 6 deletions Source/Classes/Company.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

import Foundation

public class Company {
open class Company {
// MARK: Provider

public class Provider {
open class Provider {
public init() {
// noop
}
Expand All @@ -43,7 +43,7 @@ public class Company {

// MARK: Variables

public static var provider : Provider?
open static var provider : Provider?

// MARK: Generators

Expand All @@ -52,7 +52,7 @@ public class Company {

- returns: Returns a random company name.
*/
public class func company() -> String {
open class func company() -> String {
return dataProvider().formats().random()!
}

Expand All @@ -61,11 +61,11 @@ public class Company {

- returns: Returns a random company suffix.
*/
public class func companySuffix() -> String {
open class func companySuffix() -> String {
return dataProvider().suffixes().random()!
}

private class func dataProvider() -> Provider {
fileprivate class func dataProvider() -> Provider {
return provider ?? Provider()
}
}
76 changes: 38 additions & 38 deletions Source/Classes/Internet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

import Foundation

public class Internet {
open class Internet {
// MARK: Provider

public class Provider {
open class Provider {
public init() {
// noop
}
Expand Down Expand Up @@ -77,7 +77,7 @@ public class Internet {

// MARK: Variables

public static var provider : Provider?
open static var provider : Provider?

// MARK: Generators

Expand All @@ -89,7 +89,7 @@ public class Internet {

- returns: Returns a random e-mail address.
*/
public class func email() -> String {
open class func email() -> String {
return dataProvider().emailFormats().random()!
}

Expand All @@ -98,7 +98,7 @@ public class Internet {

- returns: Returns a random safe e-mail address.
*/
public class func safeEmail() -> String {
open class func safeEmail() -> String {
return "\(username())@\(safeEmailDomain())"
}

Expand All @@ -110,7 +110,7 @@ public class Internet {

- returns: Returns a random free e-mail address.
*/
public class func freeEmail() -> String {
open class func freeEmail() -> String {
return "\(username())@\(freeEmailDomain())"
}

Expand All @@ -122,7 +122,7 @@ public class Internet {

- returns: Returns a random company e-mail address.
*/
public class func companyEmail() -> String {
open class func companyEmail() -> String {
return "\(username())@\(domainName())"
}

Expand All @@ -131,7 +131,7 @@ public class Internet {

- returns: Returns a random free e-mail domain.
*/
public class func freeEmailDomain() -> String {
open class func freeEmailDomain() -> String {
return dataProvider().freeEmailDomains().random()!
}

Expand All @@ -140,7 +140,7 @@ public class Internet {

- returns: Returns a random safe e-mail domain.
*/
public class func safeEmailDomain() -> String {
open class func safeEmailDomain() -> String {
return [ "example.com", "example.org", "example.net" ].random()!
}

Expand All @@ -149,10 +149,10 @@ public class Internet {

- returns: Returns a random username.
*/
public class func username() -> String {
open class func username() -> String {
let result = dataProvider().usernameFormats().random()!

return result.numerify().lexify().lowercaseString.stringByReplacingOccurrencesOfString(" ", withString: ".")
return result.numerify().lexify().lowercased().replacingOccurrences(of: " ", with: ".")
}

/**
Expand All @@ -165,8 +165,8 @@ public class Internet {
- returns: Returns a password of at least `minLength` and at most
`maxLength` characters.
*/
public class func password(minLength : Int = 6, maxLength : Int = 20) -> String {
let format = Array(count: Int.random(minLength, max: maxLength), repeatedValue: "*").joinWithSeparator("")
open class func password(minLength : Int = 6, maxLength : Int = 20) -> String {
let format = Array(repeating: "*", count: Int.random(min: minLength, max: maxLength)).joined(separator: "")

return format.lexify()
}
Expand All @@ -176,7 +176,7 @@ public class Internet {

- returns: Returns a random domain name.
*/
public class func domainName() -> String {
open class func domainName() -> String {
return "\(domainWord()).\(tld())"
}

Expand All @@ -185,16 +185,16 @@ public class Internet {

- returns: Returns a random domain word.
*/
public class func domainWord() -> String {
return "\(Person.lastName())".lowercaseString.stringByReplacingOccurrencesOfString(" ", withString: "-")
open class func domainWord() -> String {
return "\(Person.lastName())".lowercased().replacingOccurrences(of: " ", with: "-")
}

/**
Generate a random top-level domain (TLD).

- returns: Returns a random TLD.
*/
public class func tld() -> String {
open class func tld() -> String {
return dataProvider().tlds().random()!
}

Expand All @@ -203,7 +203,7 @@ public class Internet {

- returns: Returns a random URL.
*/
public class func url() -> String {
open class func url() -> String {
return dataProvider().urlFormats().random()!
}

Expand All @@ -216,71 +216,71 @@ public class Internet {

- returns: Returns a random slug of `nbWords` words.
*/
public class func slug(nbWords : Int = 6, variable : Bool = true) -> String {
open class func slug(_ nbWords : Int = 6, variable : Bool = true) -> String {
if nbWords <= 0 {
return ""
}

return Lorem.words(variable ? nbWords.randomize(40) : nbWords).joinWithSeparator("-").lowercaseString
return Lorem.words(variable ? nbWords.randomize(40) : nbWords).joined(separator: "-").lowercased()
}

/**
Generate a random IPv4 address.

- returns: Returns a random IPv4 address.
*/
public class func ipv4() -> String {
open class func ipv4() -> String {
return [
Int.random(0, max: 255),
Int.random(0, max: 255),
Int.random(0, max: 255),
Int.random(0, max: 255)
].map(String.init).joinWithSeparator(".")
Int.random(min: 0, max: 255),
Int.random(min: 0, max: 255),
Int.random(min: 0, max: 255),
Int.random(min: 0, max: 255)
].map(String.init).joined(separator: ".")
}

/**
Generate a random IPv6 address.

- returns: Returns a random IPv6 address.
*/
public class func ipv6() -> String {
let components = (0..<8).map { _ in Int.random(0, max: 65535) }
open class func ipv6() -> String {
let components = (0..<8).map { _ in Int.random(min: 0, max: 65535) }

return components.map({ String(format: "%04x", arguments: [ $0 ]) }).joinWithSeparator(":")
return components.map({ String(format: "%04x", arguments: [ $0 ]) }).joined(separator: ":")
}

/**
Generate a random local IPv4 address.

- returns: Returns a random local IPv4 address.
*/
public class func localIpv4() -> String {
open class func localIpv4() -> String {
var prefix : String = ""
var components : [String] = [String]()

if Int.random(0, max: 1) == 0 {
if Int.random(min: 0, max: 1) == 0 {
prefix = "10."
components = (0..<3).map({ _ in Int.random(0, max: 255) }).map(String.init)
components = (0..<3).map({ _ in Int.random(min: 0, max: 255) }).map(String.init)
} else {
prefix = "192.168."
components = (0..<2).map({ _ in Int.random(0, max: 255) }).map(String.init)
components = (0..<2).map({ _ in Int.random(min: 0, max: 255) }).map(String.init)
}

return prefix + components.joinWithSeparator(".")
return prefix + components.joined(separator: ".")
}

/**
Generate a random MAC address.

- returns: Returns a random MAC address.
*/
public class func mac() -> String {
let components = (0..<6).map { _ in Int.random(0, max: 255) }
open class func mac() -> String {
let components = (0..<6).map { _ in Int.random(min: 0, max: 255) }

return components.map({ String(format: "%02X", arguments: [ $0 ]) }).joinWithSeparator(":")
return components.map({ String(format: "%02X", arguments: [ $0 ]) }).joined(separator: ":")
}

private class func dataProvider() -> Provider {
fileprivate class func dataProvider() -> Provider {
return provider ?? Provider()
}
}
Loading