From a2af1a9e80c18513877f1ea4b6763fd21d97a0d2 Mon Sep 17 00:00:00 2001 From: Grant McNally Date: Wed, 1 Feb 2017 14:19:15 +1100 Subject: [PATCH 1/2] Add Random Alphanumeric String generation --- SwiftRandom/Randoms.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/SwiftRandom/Randoms.swift b/SwiftRandom/Randoms.swift index c02611b..c8bf1be 100644 --- a/SwiftRandom/Randoms.swift +++ b/SwiftRandom/Randoms.swift @@ -153,6 +153,20 @@ public extension URL { } } +public extension String { + public static func random(_ length: Int = 5) -> String { + let charSet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + var char = charSet.characters.map { String($0) } + var randomString = "" + + for _ in (1...length) { + randomString = randomString + char[Int(arc4random()) % char.count] + } + + return randomString + } +} + public struct Randoms { @@ -211,6 +225,10 @@ public struct Randoms { public static func randomNSURL() -> URL { return URL.random() } + + public func randomString(_ length: Int = 5) -> String { + return String.random(length) + } //========================================================================================================== // MARK: - Fake random data generators From 5da3e5673b78304983f546581a0821a2abf69165 Mon Sep 17 00:00:00 2001 From: Grant McNally Date: Wed, 28 Aug 2019 16:36:17 +1000 Subject: [PATCH 2/2] Change to Swift 4 --- SwiftRandom.xcodeproj/project.pbxproj | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/SwiftRandom.xcodeproj/project.pbxproj b/SwiftRandom.xcodeproj/project.pbxproj index 566531a..2e63879 100755 --- a/SwiftRandom.xcodeproj/project.pbxproj +++ b/SwiftRandom.xcodeproj/project.pbxproj @@ -235,7 +235,7 @@ PRODUCT_BUNDLE_IDENTIFIER = thellimist.SwiftRandom.SwiftRandomTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -253,7 +253,7 @@ PRODUCT_BUNDLE_IDENTIFIER = thellimist.SwiftRandom.SwiftRandomTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -299,6 +299,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -339,6 +340,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -356,12 +358,13 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = SwiftRandom/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = thellimist.SwiftRandom; PRODUCT_NAME = SwiftRandom; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -375,12 +378,13 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = SwiftRandom/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = thellimist.SwiftRandom; PRODUCT_NAME = SwiftRandom; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -394,6 +398,7 @@ 53DC009B1DA3313F00C3C823 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; B537B0C51BCA9E3E005725CE /* Build configuration list for PBXProject "SwiftRandom" */ = { isa = XCConfigurationList;