Skip to content

Commit

Permalink
Merge pull request #241 from ankurp/swift-package-manager-proj
Browse files Browse the repository at this point in the history
Updating project to use swift package manager and adding permutation function
  • Loading branch information
ankurp authored Oct 23, 2016
2 parents 9d6a8ed + 0660da7 commit b595220
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 375 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ language: objective-c
osx_image: xcode8

script:
- xcodebuild clean build test -scheme Dollar -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6'
- swift build
- swift test
7 changes: 7 additions & 0 deletions Dollar.xcodeproj/Configs/Project.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
PRODUCT_NAME = $(TARGET_NAME)
SUPPORTED_PLATFORMS = macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator
MACOSX_DEPLOYMENT_TARGET = 10.10
DYLIB_INSTALL_NAME_BASE = @rpath
OTHER_SWIFT_FLAGS = -DXcode
COMBINE_HIDPI_IMAGES = YES
USE_HEADERMAP = NO
25 changes: 25 additions & 0 deletions Dollar.xcodeproj/DollarTests_Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
25 changes: 25 additions & 0 deletions Dollar.xcodeproj/Dollar_Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
495 changes: 149 additions & 346 deletions Dollar.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

33 changes: 5 additions & 28 deletions Dollar.xcodeproj/xcshareddata/xcschemes/Dollar.xcscheme
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
version = "1.8">
LastUpgradeVersion = "9999"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
Expand All @@ -14,27 +14,13 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "92E0D03B19467C67002ACC3D"
BlueprintIdentifier = "______Target_Dollar"
BuildableName = "Dollar.framework"
BlueprintName = "Dollar"
ReferencedContainer = "container:Dollar.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "92E6686E19F09C6400BB4FB8"
BuildableName = "DollarTests.xctest"
BlueprintName = "DollarTests"
ReferencedContainer = "container:Dollar.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
Expand All @@ -46,22 +32,13 @@
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "92E6686E19F09C6400BB4FB8"
BlueprintIdentifier = "______Target_DollarTests"
BuildableName = "DollarTests.xctest"
BlueprintName = "DollarTests"
ReferencedContainer = "container:Dollar.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "92E0D03B19467C67002ACC3D"
BuildableName = "Dollar.framework"
BlueprintName = "Dollar"
ReferencedContainer = "container:Dollar.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
Expand All @@ -78,7 +55,7 @@
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "92E0D03B19467C67002ACC3D"
BlueprintIdentifier = "______Target_Dollar"
BuildableName = "Dollar.framework"
BlueprintName = "Dollar"
ReferencedContainer = "container:Dollar.xcodeproj">
Expand Down
12 changes: 12 additions & 0 deletions Dollar.xcodeproj/xcshareddata/xcschemes/xcschememanagement.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>Dollar.xcscheme</key>
<dict></dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict></dict>
</dict>
</plist>
23 changes: 23 additions & 0 deletions Sources/Dollar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,29 @@ open class $ {
return $.pull(array, values: elemToRemove)
}

/// Returns permutation of array
///
/// - parameter character: Characters to source the permutation
/// - returns: Array of permutation of the characters specified
open class func permutation<T>(_ elements: [T]) -> [String] where T : CustomStringConvertible {
guard elements.count > 1 else {
return $.map(elements) { $0.description }
}

let strings = self.permutation($.initial(elements))
if let char = $.last(elements) {
return $.reduce(strings, initial: []) { (result, str) -> [String] in
let splitStr = $.map(str.description.characters) { $0.description }
return result + $.map(0...splitStr.count) { (index) -> String in
var copy = $.copy(splitStr)
copy.insert(char.description, at: (splitStr.count - index))
return $.join(copy, separator: "")
}
}.sorted()
}
return []
}

/// Returns random number from 0 upto but not including upperBound
///
/// - parameter upperBound: upper bound when generating random number
Expand Down
5 changes: 5 additions & 0 deletions Tests/DollarTests/DollarTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class DollarTests: XCTestCase {
super.tearDown()
}

func testPermutation() {
let result = $.permutation(["a", "b", "c"])
XCTAssertEqual(result, ["abc", "acb", "bac", "bca", "cab", "cba"])
}

func testFirst() {
if let result = $.first([1, 2, 3, 4]) {
XCTAssertEqual(result, 1, "Return first element")
Expand Down
1 change: 1 addition & 0 deletions Try.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import Dollar
4 changes: 4 additions & 0 deletions Try.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios'>
<timeline fileName='timeline.xctimeline'/>
</playground>

0 comments on commit b595220

Please sign in to comment.