From e6eeb8094fb6f27e393c669ac950827ea822c65d Mon Sep 17 00:00:00 2001 From: Lukas Kubanek Date: Tue, 29 Aug 2017 15:17:50 +0200 Subject: [PATCH 1/2] Updated the code for Swift 4 --- LoremSwiftum.xcodeproj/project.pbxproj | 42 ++-- .../xcschemes/LoremSwiftum-Mac.xcscheme | 4 +- .../xcschemes/LoremSwiftum-iOS.xcscheme | 4 +- .../LoremSwiftum.playground/Contents.swift | 65 ++--- Sources/LoremSwiftum.h | 15 -- Sources/LoremSwiftum.swift | 230 ++++++++++-------- Supporting Files/Info.plist | 4 +- 7 files changed, 189 insertions(+), 175 deletions(-) diff --git a/LoremSwiftum.xcodeproj/project.pbxproj b/LoremSwiftum.xcodeproj/project.pbxproj index c9ddf79..5d03721 100644 --- a/LoremSwiftum.xcodeproj/project.pbxproj +++ b/LoremSwiftum.xcodeproj/project.pbxproj @@ -7,22 +7,20 @@ objects = { /* Begin PBXBuildFile section */ + 80175E571F556EF4009DC804 /* LoremSwiftum.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80175E561F556EF4009DC804 /* LoremSwiftum.swift */; }; 802CD5CE1A1E9F690067165F /* LoremSwiftum.h in Headers */ = {isa = PBXBuildFile; fileRef = 80B67B4419E5603D00D2DEC2 /* LoremSwiftum.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 808383EB1BAA98B80075603A /* LoremSwiftum.swift in Sources */ = {isa = PBXBuildFile; fileRef = 808383EA1BAA98B80075603A /* LoremSwiftum.swift */; }; - 80863FDE1BD7869F00C3D182 /* LoremSwiftum.swift in Sources */ = {isa = PBXBuildFile; fileRef = 808383EA1BAA98B80075603A /* LoremSwiftum.swift */; }; 80863FDF1BD786A300C3D182 /* LoremSwiftum.h in Headers */ = {isa = PBXBuildFile; fileRef = 80B67B4419E5603D00D2DEC2 /* LoremSwiftum.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 80DF35101BF8F04A004F17C5 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 80DF350F1BF8F04A004F17C5 /* Foundation.framework */; }; - 80DF35111BF8F054004F17C5 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 80DF350F1BF8F04A004F17C5 /* Foundation.framework */; }; + 80CB484D1F55727400844DFB /* LoremSwiftum.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80175E561F556EF4009DC804 /* LoremSwiftum.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 80175E561F556EF4009DC804 /* LoremSwiftum.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoremSwiftum.swift; sourceTree = ""; }; 802CD5B41A1E9F090067165F /* LoremSwiftum.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LoremSwiftum.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 808383EA1BAA98B80075603A /* LoremSwiftum.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoremSwiftum.swift; sourceTree = ""; }; 808384011BAAB2440075603A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 80863FD21BD7864C00C3D182 /* LoremSwiftum.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LoremSwiftum.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 80B67B4419E5603D00D2DEC2 /* LoremSwiftum.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoremSwiftum.h; sourceTree = ""; }; 80DF350F1BF8F04A004F17C5 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; - 80DF35121BF8F082004F17C5 /* LoremSwiftum.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = LoremSwiftum.playground; sourceTree = ""; }; + 80DF35121BF8F082004F17C5 /* LoremSwiftum.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = LoremSwiftum.playground; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -30,7 +28,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 80DF35111BF8F054004F17C5 /* Foundation.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -38,7 +35,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 80DF35101BF8F04A004F17C5 /* Foundation.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -93,7 +89,7 @@ isa = PBXGroup; children = ( 80B67B4419E5603D00D2DEC2 /* LoremSwiftum.h */, - 808383EA1BAA98B80075603A /* LoremSwiftum.swift */, + 80175E561F556EF4009DC804 /* LoremSwiftum.swift */, ); path = Sources; sourceTree = ""; @@ -163,7 +159,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Lukas Kubanek"; TargetAttributes = { 802CD5B31A1E9F090067165F = { @@ -216,7 +212,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 808383EB1BAA98B80075603A /* LoremSwiftum.swift in Sources */, + 80CB484D1F55727400844DFB /* LoremSwiftum.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -224,7 +220,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 80863FDE1BD7869F00C3D182 /* LoremSwiftum.swift in Sources */, + 80175E571F556EF4009DC804 /* LoremSwiftum.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -247,6 +243,7 @@ ); INFOPLIST_FILE = "Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_BUNDLE_IDENTIFIER = "com.lukaskubanek.$(PRODUCT_NAME:rfc1034identifier)"; @@ -254,7 +251,6 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; - SWIFT_VERSION = 2.3; }; name = Debug; }; @@ -271,6 +267,7 @@ FRAMEWORK_VERSION = A; INFOPLIST_FILE = "Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_BUNDLE_IDENTIFIER = "com.lukaskubanek.$(PRODUCT_NAME:rfc1034identifier)"; @@ -278,7 +275,6 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; - SWIFT_VERSION = 2.3; }; name = Release; }; @@ -301,7 +297,6 @@ PRODUCT_NAME = LoremSwiftum; SDKROOT = macosx; SKIP_INSTALL = YES; - SWIFT_VERSION = 2.3; }; name = Debug; }; @@ -325,7 +320,6 @@ PRODUCT_NAME = LoremSwiftum; SDKROOT = macosx; SKIP_INSTALL = YES; - SWIFT_VERSION = 2.3; }; name = Release; }; @@ -337,14 +331,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; 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_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -368,11 +368,11 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = YES; 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 = ""; @@ -387,14 +387,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; 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_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -411,10 +417,10 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; diff --git a/LoremSwiftum.xcodeproj/xcshareddata/xcschemes/LoremSwiftum-Mac.xcscheme b/LoremSwiftum.xcodeproj/xcshareddata/xcschemes/LoremSwiftum-Mac.xcscheme index a0e1253..785ab03 100644 --- a/LoremSwiftum.xcodeproj/xcshareddata/xcschemes/LoremSwiftum-Mac.xcscheme +++ b/LoremSwiftum.xcodeproj/xcshareddata/xcschemes/LoremSwiftum-Mac.xcscheme @@ -1,6 +1,6 @@ @@ -36,6 +37,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/LoremSwiftum.xcodeproj/xcshareddata/xcschemes/LoremSwiftum-iOS.xcscheme b/LoremSwiftum.xcodeproj/xcshareddata/xcschemes/LoremSwiftum-iOS.xcscheme index 620d41d..25e99a0 100644 --- a/LoremSwiftum.xcodeproj/xcshareddata/xcschemes/LoremSwiftum-iOS.xcscheme +++ b/LoremSwiftum.xcodeproj/xcshareddata/xcschemes/LoremSwiftum-iOS.xcscheme @@ -1,6 +1,6 @@ One random word + +Lorem.words(3) +// => Three random words + +Lorem.sentence +// => One random sentence + +Lorem.sentences(3) +// => Three random sentences -let word = Lorem.word -let words0 = Lorem.words(0) -let words1 = Lorem.words(1) -let words5 = Lorem.words(5) +Lorem.paragraph +// => One random paragraph -let sentence = Lorem.sentence -let sentences0 = Lorem.sentences(0) -let sentences1 = Lorem.sentences(1) -let sentences5 = Lorem.sentences(5) +Lorem.paragraphs(3) +// => Three random paragraphs -let paragraph = Lorem.paragraph -let paragraphs0 = Lorem.paragraphs(0) -let paragraphs1 = Lorem.paragraphs(1) -let paragraphs5 = Lorem.paragraphs(5) +Lorem.title +// => A random title -let title = Lorem.title +Lorem.firstName +// => A random first name -// ======================================================= // -// Misc Data -// ======================================================= // +Lorem.lastName +// => A random last name -let name = Lorem.name -let firstName = Lorem.firstName -let lastName = Lorem.lastName +Lorem.fullName +// => A random full name -let email = Lorem.email -let url = Lorem.URL -let tweet = Lorem.tweet +Lorem.emailAddress +// => A random email address -let date = Lorem.date +Lorem.tweet +// => A random tweet diff --git a/Sources/LoremSwiftum.h b/Sources/LoremSwiftum.h index 4adfdd7..8b13789 100644 --- a/Sources/LoremSwiftum.h +++ b/Sources/LoremSwiftum.h @@ -1,16 +1 @@ -// -// __ _____ _ ______ -// / / ____ ________ ____ ___ / ___/ __(_) __/ /___ ______ ___ -// / / / __ \/ ___/ _ \/ __ `__ \\__ \ | /| / / / /_/ __/ / / / __ `__ \ -// / /___/ /_/ / / / __/ / / / / /__/ / |/ |/ / / __/ /_/ /_/ / / / / / / -// /_____/\____/_/ \___/_/ /_/ /_/____/|__/|__/_/_/ \__/\__,_/_/ /_/ /_/ -// -// LoremSwiftum.h -// http://github.com/lukaskubanek/LoremSwiftum -// 2014-2015 (c) Lukas Kubanek (http://lukaskubanek.com) -// -@import Foundation; - -FOUNDATION_EXPORT double LoremSwiftumVersionNumber; -FOUNDATION_EXPORT const unsigned char LoremSwiftumVersionString[]; diff --git a/Sources/LoremSwiftum.swift b/Sources/LoremSwiftum.swift index 0053728..b675a78 100644 --- a/Sources/LoremSwiftum.swift +++ b/Sources/LoremSwiftum.swift @@ -1,173 +1,205 @@ -// -// __ _____ _ ______ -// / / ____ ________ ____ ___ / ___/ __(_) __/ /___ ______ ___ -// / / / __ \/ ___/ _ \/ __ `__ \\__ \ | /| / / / /_/ __/ / / / __ `__ \ -// / /___/ /_/ / / / __/ / / / / /__/ / |/ |/ / / __/ /_/ /_/ / / / / / / -// /_____/\____/_/ \___/_/ /_/ /_/____/|__/|__/_/_/ \__/\__,_/_/ /_/ /_/ -// -// LoremSwiftum.swift -// http://github.com/lukaskubanek/LoremSwiftum -// 2014-2015 (c) Lukas Kubanek (http://lukaskubanek.com) -// +import Foundation -public class Lorem { - - // ======================================================= // - // MARK: - Text - // ======================================================= // +/// A leightweight lorem ipsum generator. +public final class Lorem { + /// Generates a single word. public static var word: String { - return allWords.randomElement + return allWords.random } - public static func words(count: Int) -> String { - return compose({ word }, count: count, middleSeparator: .Space) + /// Generates multiple words whose count is defined by the given value. + /// + /// - Parameter count: The number of words to generate. + /// - Returns: The generated words joined by a space character. + public static func words(_ count: Int) -> String { + return compose({ word }, + count: count, + joinBy: .space) } + /// Generates a single sentence. public static var sentence: String { - let numberOfWordsInSentence = Int.random(min: 4, max: 16) - let capitalizeFirstLetterDecorator: String -> String = { $0.stringWithCapitalizedFirstLetter } - return compose({ word }, count: numberOfWordsInSentence, middleSeparator: .Space, endSeparator: .Dot, decorator: capitalizeFirstLetterDecorator) + let numberOfWords = Int.random(min: minWordsCountInSentence, + max: maxWordsCountInSentence) + + return compose({ word }, + count: numberOfWords, + joinBy: .space, + endWith: .dot, + decorate: { $0.firstLetterCapitalized() }) } - public static func sentences(count: Int) -> String { - return compose({ sentence }, count: count, middleSeparator: .Space) + /// Generates multiple sentences whose count is defined by the given value. + /// + /// - Parameter count: The number of sentences to generate. + /// - Returns: The generated sentences joined by a space character. + public static func sentences(_ count: Int) -> String { + return compose({ sentence }, + count: count, + joinBy: .space) } + /// Generates a single paragraph. public static var paragraph: String { - let numberOfSentencesInParagraph = Int.random(min: 3, max: 9) - return sentences(numberOfSentencesInParagraph) + let numberOfSentences = Int.random(min: minSentencesCountInParagraph, + max: maxSentencesCountInParagraph) + + return compose({ sentence }, + count: numberOfSentences, + joinBy: .space) } - public static func paragraphs(count: Int) -> String { - return compose({ paragraph }, count: count, middleSeparator: .NewLine) + /// Generates multiple paragraphs whose count is defined by the given value. + /// + /// - Parameter count: The number of paragraphs to generate. + /// - Returns: The generated paragraphs joined by a space character. + public static func paragraphs(_ count: Int) -> String { + return compose({ paragraph }, + count: count, + joinBy: .newLine) } + /// Generates a single title. public static var title: String { - let numberOfWordsInTitle = Int.random(min: 2, max: 7) - let capitalizeStringDecorator: String -> String = { $0.capitalizedString } - return compose({ word }, count: numberOfWordsInTitle, middleSeparator: .Space, decorator: capitalizeStringDecorator) + let numberOfWords = Int.random(min: minWordsCountInTitle, + max: maxWordsCountInTitle) + + return compose({ word }, + count: numberOfWords, + joinBy: .space, + decorate: { $0.capitalized }) } - // ======================================================= // - // MARK: - Misc - // ======================================================= // - + /// Generates a first name. public static var firstName: String { - return firstNames.randomElement + return firstNames.random } + /// Generates a last name. public static var lastName: String { - return lastNames.randomElement + return lastNames.random } - public static var name: String { - return "\(firstName) \(lastName)" + /// Generates a full name. + public static var fullName: String { + return "\(firstName) \(lastName))" } - public static var email: String { - let delimiter = emailDelimiters.randomElement - let domain = emailDomains.randomElement - return "\(firstName)\(delimiter)\(lastName)@\(domain)".lowercaseString + /// Generates an email address. + public static var emailAddress: String { + return "\(firstName)\(emailDelimiters.random)\(lastName)@\(emailDomains.random)".lowercased() } - public static var URL: NSURL { - return NSURL(string: "http://\(domains.randomElement)/")! + /// Generates a URL. + public static var url: String { + return "\(urlScheme)://\(urlDomains.random)" } + /// Generates a random tweet which is shorter than 140 characters. public static var tweet: String { - return tweets.randomElement - } - - public static var date: NSDate { - let currentDate = NSDate() - let currentCalendar = NSCalendar.currentCalendar() - let referenceDateComponents = NSDateComponents() - referenceDateComponents.year = -4 - let calendarOptions = NSCalendarOptions(rawValue: 0) - let referenceDate = currentCalendar.dateByAddingComponents(referenceDateComponents, toDate: currentDate, options: calendarOptions)! - let timeIntervalSinceReferenceDate = currentDate.timeIntervalSinceDate(referenceDate) - let randomTimeInterval = NSTimeInterval(Int.random(max: Int(timeIntervalSinceReferenceDate))) - return referenceDate.dateByAddingTimeInterval(randomTimeInterval) + var tweet = "" + + while tweet.count < tweetLength { + tweet += paragraph + } + + tweet = String(tweet.prefix(tweetLength - 1)) + tweet = tweet.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) + + if let lastCharacter = tweet.last { + if String(lastCharacter) != Separator.dot.rawValue { + tweet += Separator.dot.rawValue + } + } + + return tweet } - // ======================================================= // - // MARK: - Private - // ======================================================= // +} + +fileprivate extension Lorem { - private enum Separator: String { - case None = "" - case Space = " " - case Dot = "." - case NewLine = "\n" + fileprivate enum Separator: String { + case none = "" + case space = " " + case dot = "." + case newLine = "\n" } - private static func compose(provider: () -> String, count: Int, middleSeparator: Separator, endSeparator: Separator = .None, decorator: (String -> String)? = nil) -> String { - var composedString = "" + fileprivate static func compose(_ provider: () -> String, + count: Int, + joinBy middleSeparator: Separator, + endWith endSeparator: Separator = .none, + decorate decorator: ((String) -> String)? = nil) -> String { + var string = "" for index in 0.. Int { - assert(min >= 0) - assert(min < max) - - return Int(arc4random_uniform(UInt32((max - min) + 1))) + min + fileprivate var random: Element { + precondition(!isEmpty) + return self[Int.random(max: count - 1)] } } -private extension Array { - private var randomElement: Element { - return self[Int.random(max: count - 1)] +fileprivate extension Int { + + fileprivate static func random(min: Int = 0, max: Int) -> Int { + precondition(min >= 0 && min < max) + return Int(arc4random_uniform(UInt32((max - min) + 1))) + min } } -private extension String { +fileprivate extension String { - private var stringWithCapitalizedFirstLetter: String { - let firstLetterRange = startIndex.. String { + guard !isEmpty else { return self } + return self[startIndex...startIndex].uppercased() + self[index(after: startIndex)..CFBundlePackageType FMWK CFBundleShortVersionString - 1.0 + 2.0.0-beta.1 CFBundleSignature ???? CFBundleVersion $(CURRENT_PROJECT_VERSION) - NSPrincipalClass - From b5445ca3b0fcb3b41785a767b87a7c64787dc0cd Mon Sep 17 00:00:00 2001 From: Lukas Kubanek Date: Tue, 29 Aug 2017 15:34:26 +0200 Subject: [PATCH 2/2] Updated README --- LICENSE.md | 4 +- .../contents.xcworkspacedata | 4 ++ README.md | 59 ++++++++++++++++--- 3 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 Playgrounds/LoremSwiftum.playground/playground.xcworkspace/contents.xcworkspacedata diff --git a/LICENSE.md b/LICENSE.md index f454808..802d893 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,7 +1,7 @@ -Copyright (c) 2014 Lukas Kubanek. +Copyright (c) 2014-2017 Lukas Kubanek. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Playgrounds/LoremSwiftum.playground/playground.xcworkspace/contents.xcworkspacedata b/Playgrounds/LoremSwiftum.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..94b2795 --- /dev/null +++ b/Playgrounds/LoremSwiftum.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,4 @@ + + + diff --git a/README.md b/README.md index 3de474a..a52cf6b 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,74 @@ # LoremSwiftum -[![](https://img.shields.io/github/release/lukaskubanek/LoremSwiftum.svg?style=flat-square)](https://github.com/lukaskubanek/LoremSwiftum/releases) [![](https://img.shields.io/badge/Swift-2.3-orange.svg?style=flat-square)](https://developer.apple.com/swift/) ![](https://img.shields.io/badge/platform-macOS/iOS-yellowgreen.svg?style=flat-square) [![](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat-square "Carthage compatible")](https://github.com/Carthage/Carthage) [![](https://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat-square "License")](LICENSE.md) +[![](https://img.shields.io/badge/release-v2.0.0--beta-blue.svg?style=flat-square)](https://github.com/lukaskubanek/OrderedDictionary/releases) [![](https://img.shields.io/badge/Swift-4.0-orange.svg?style=flat-square)](https://developer.apple.com/swift/ "Swift 4") ![](https://img.shields.io/badge/platform-macOS,%20iOS-yellowgreen.svg?style=flat-square "Platform: macOS, iOS") [![](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat-square "Carthage compatible")](https://github.com/Carthage/Carthage) [![](https://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat-square "License: MIT")](LICENSE.md) -**LoremSwiftum** is a lightweight lorem ipsum generator for iOS and OS X written in Swift. It supports generating texts in different formats (words, sentences, paragraphs) and miscellaneous data (names, URLs, dates etc.). This framework is a reimplementation of the library [LoremIpsum](https://github.com/lukaskubanek/LoremIpsum) written in Objective-C. +**LoremSwiftum** is a lightweight lorem ipsum generator for iOS and macOS written in Swift. It supports generating following random texts: words, sentences, paragraphs, titles, names, email addresses, URLs and tweets. Originally, this library was created as a Swift port of [LoremIpsum](https://github.com/lukaskubanek/LoremIpsum) written in Objective-C. ## Requirements -- Swift 2.3 -- Xcode 8 +- Swift 4 +- Xcode 9 beta 6 - iOS 8.0+ / OS X 10.10+ ## Installation +This library is distributed as a Swift framework and can be integrated into your project in following ways: + ### Carthage -The easiest way to integrate this framework in your project is to use [Carthage](https://github.com/Carthage/Carthage/). +The easiest way is to use the package manager [Carthage](https://github.com/Carthage/Carthage). 1. Add `github "lukaskubanek/LoremSwiftum"` to your `Cartfile`. 2. Run `carthage bootstrap`. 3. Drag either the `LoremSwiftum.xcodeproj` or the `LoremSwiftum.framework` into your project/workspace and link your target against the `LoremSwiftum.framework`. 4. Make sure the framework [gets copied](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application) to your application bundle. +5. Import the framework using `import LoremSwiftum`. -### Submodules +### Submodule & Xcode Project -Another option for integrating this framework is to use [Git submodules](http://git-scm.com/book/en/v2/Git-Tools-Submodules). +Another option is to use [Git submodules](http://git-scm.com/book/en/v2/Git-Tools-Submodules) and integrating the Xcode project `LoremSwiftum.xcodeproj` directly to your Xcode workspace. ## Usage -For the overview of the API provided by this library see the playground file [Examples.playground](Examples/LoremSwiftum.playground/Contents.swift). +``` +import LoremSwiftum + +Lorem.word +// => One random word + +Lorem.words(3) +// => Three random words + +Lorem.sentence +// => One random sentence + +Lorem.sentences(3) +// => Three random sentences + +Lorem.paragraph +// => One random paragraph + +Lorem.paragraphs(3) +// => Three random paragraphs + +Lorem.title +// => A random title + +Lorem.firstName +// => A random first name + +Lorem.lastName +// => A random last name + +Lorem.fullName +// => A random full name + +Lorem.emailAddress +// => A random email address + +Lorem.tweet +// => A random tweet +``` ## Author @@ -35,4 +76,4 @@ Lukas Kubanek // [lukaskubanek.com](http://lukaskubanek.com) // [@kubanekl](http ## License -`LoremSwiftum` is released under the [MIT License](LICENSE.md). +**LoremSwiftum** is released under the [MIT License](LICENSE.md).