-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [wip] remove swift 3 directive * [wip] mechanical transition with code migrator * Swift 3 preview 1 changes * travis xcode8 update * travis update OS X 10.12 * updated documentation to swift 3 and Xcode 8 * Removed "Foundation not needed" comment Unlike Objc, swift doesn’t need foundation for most simple operations. I was planning to remove the foundation requirement but now swift 3.0 will provide a Swift version of foundation. https://github.com/apple/swift-corelibs-foundation * ran swiftLink locally with autocorrect - This next step is to turn this on on Travis CI to warn on commit * travis update with swiftlint * update travis * added swiftlint rules yml * update read me with contribution guides closes #66 * update swiftLint rules * force swift3 for XCTest classes by using compiler directive. By wrapping the import to only import when swift 3 is present I am hoping to impress to users that swift 3 is required. Plus this would make it easy to go back and keep requiring a certain a version in the future. * BinarySearchTree using indirect enums closes #152 reference: https://airspeedvelocity.net/2015/07/22/a-persistent-tree-using-indirect -enums-in-swift/ * update swiftlint format requirement update swift lint doc and script in Xcode project `swiftlint autocorrect --format` * operator_whitespace removal * removed leading white space * mid triple new lines clean up * closes #10
- Loading branch information
Showing
138 changed files
with
3,335 additions
and
4,028 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
variable_name: | ||
min_length: | ||
warning: 1 | ||
error: 0 | ||
|
||
force_try: warning | ||
|
||
disabled_rules: # rule identifiers to exclude from running | ||
- function_body_length | ||
- line_length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
language: objective-c | ||
osx_image: xcode7.3 | ||
osx_image: xcode8 | ||
xcode_project: 'xcodeProject/xSwift.xcodeproj' | ||
xcode_scheme: 'xSwiftTests' | ||
|
||
install: | ||
- brew update && brew install swiftlint | ||
|
||
script: | ||
- xcodebuild test -project 'xcodeProject/xSwift.xcodeproj' -scheme 'xSwiftTests' -sdk macosx10.11 | ||
- swiftlint | ||
- xcodebuild test -project 'xcodeProject/xSwift.xcodeproj' -scheme 'xSwiftTests' -sdk macosx10.12 | ||
- bin/fetch-configlet | ||
- bin/configlet . | ||
sudo: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
## Installing Swift | ||
|
||
In order to use Swift, you must be running Xcode version 7.3 or greater which is available at [Apple's developer center](https://developer.apple.com/xcode/downloads/). | ||
In order to use Swift, you must be running Xcode version 8.0 or greater which is available at [Apple's developer center](https://developer.apple.com/xcode/downloads/). | ||
|
||
|
||
All exercises tested with Xcode 7.3 using Swift 2.2 | ||
All exercises tested with Xcode 8.0 using Swift 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,91 @@ | ||
|
||
import XCTest | ||
|
||
|
||
#if swift(>=3.0) | ||
import XCTest | ||
#endif | ||
|
||
private extension String { | ||
|
||
var length: Int {return self.characters.count} | ||
|
||
func reverse() -> String { | ||
var result:String = "" | ||
var result: String = "" | ||
for char in self.characters { | ||
result = "\(char)\(result)" | ||
} | ||
return result | ||
} | ||
|
||
} | ||
|
||
class AccumulateTest: XCTestCase { | ||
|
||
func testEmptyAccumulation() { | ||
func testEmptyAccumulation() { | ||
|
||
let input = [Int]() | ||
func square(input:Int) -> Int { | ||
let input = [Int]() | ||
func square(_ input: Int) -> Int { | ||
return input * input | ||
} | ||
let result = input.accumulate(square) | ||
} | ||
let result = input.accumulate(square) | ||
|
||
XCTAssertTrue(result.isEmpty) | ||
} | ||
|
||
func testAccumulateSquares() { | ||
let input = [1,2,3,4] | ||
let expected = [1,4,9,16] | ||
func square(input:Int) -> Int { | ||
|
||
let input = [1, 2, 3, 4] | ||
let expected = [1, 4, 9, 16] | ||
func square(_ input: Int) -> Int { | ||
return input * input | ||
} | ||
|
||
let result = input.accumulate(square) | ||
|
||
XCTAssertEqual(expected, result) | ||
} | ||
|
||
|
||
func testAccumulateUpcases() { | ||
let input = ["hello","world"] | ||
let expected = ["HELLO","WORLD"] | ||
func toUpper(input:String) -> String { | ||
return input.uppercaseString | ||
|
||
let input = ["hello", "world"] | ||
let expected = ["HELLO", "WORLD"] | ||
func toUpper(_ input: String) -> String { | ||
return input.uppercased() | ||
} | ||
|
||
let result = input.accumulate(toUpper) | ||
|
||
XCTAssertEqual(expected, result) | ||
|
||
} | ||
|
||
|
||
} | ||
func testAccumulateReversedStrings() { | ||
let input = ["the","quick","brown","fox","etc"] | ||
let expected = ["eht","kciuq","nworb","xof","cte"] | ||
func reverse(input:String) -> String { | ||
|
||
let input = ["the", "quick", "brown", "fox", "etc"] | ||
let expected = ["eht", "kciuq", "nworb", "xof", "cte"] | ||
func reverse(_ input: String) -> String { | ||
return input.reverse() | ||
} | ||
|
||
let result = input.accumulate(reverse) | ||
|
||
XCTAssertEqual(expected, result) | ||
} | ||
|
||
func testAccumulateRecursively() { | ||
let input = ["a","b","c"] | ||
|
||
let input = ["a", "b", "c"] | ||
|
||
let expected = [ | ||
["a1","a2","a3"], | ||
["b1","b2","b3"], | ||
["c1","c2","c3"] | ||
["a1", "a2", "a3"], | ||
["b1", "b2", "b3"], | ||
["c1", "c2", "c3"] | ||
] | ||
func recurse(input:String) -> [String] { | ||
func appendTo(innerInput:String) -> String { | ||
|
||
func recurse(_ input: String) -> [String] { | ||
func appendTo(_ innerInput: String) -> String { | ||
return input+innerInput | ||
} | ||
let result = ["1","2","3"].accumulate(appendTo) | ||
let result = ["1", "2", "3"].accumulate(appendTo) | ||
return result | ||
} | ||
|
||
|
||
let result = input.accumulate(recurse) | ||
|
||
XCTAssertEqual(expected, result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,74 @@ | ||
// Foundation not needed | ||
private extension String { | ||
|
||
|
||
|
||
private extension String{ | ||
|
||
func substringWithRangeInt(intRange:Range<Int>)->String{ | ||
let start = self.startIndex.advancedBy(intRange.startIndex) | ||
let end = self.startIndex.advancedBy(intRange.endIndex) | ||
return self.substringWithRange(start..<end) | ||
func substringWithRangeInt(_ intRange: CountableRange<Int>) -> String { | ||
let start = self.characters.index(self.startIndex, offsetBy: intRange.lowerBound) | ||
let end = self.characters.index(self.startIndex, offsetBy: intRange.upperBound) | ||
return self.substring(with: start..<end) | ||
} | ||
func substringWithRangeInt(start start:Int, end:Int) -> String{ | ||
|
||
func substringWithRangeInt(start: Int, end: Int) -> String { | ||
let range = start..<end | ||
return self.substringWithRangeInt(range) | ||
} | ||
var isUppercase:Bool { | ||
return self == self.uppercaseString | ||
|
||
var isUppercase: Bool { | ||
return self == self.uppercased() | ||
} | ||
var isLowercase:Bool { | ||
return self == self.lowercaseString | ||
|
||
var isLowercase: Bool { | ||
return self == self.lowercased() | ||
} | ||
} | ||
|
||
struct Acronym{ | ||
static func abbreviate(inString:String) -> String { | ||
var previousLetter:String = "" | ||
func splitCamelcaseAt(currentLetter: String, inout withString previousLetter: String ) -> Bool { | ||
struct Acronym { | ||
|
||
static func abbreviate(_ inString: String) -> String { | ||
|
||
var previousLetter: String = "" | ||
|
||
func splitCamelcaseAt(_ currentLetter: String, withString previousLetter: inout String ) -> Bool { | ||
|
||
defer { previousLetter = currentLetter } | ||
|
||
if currentLetter == " " { return false | ||
} else if currentLetter.isEmpty { return false | ||
} else if (previousLetter.isLowercase && currentLetter.isUppercase){ | ||
} else if (previousLetter.isLowercase && currentLetter.isUppercase) { | ||
//previousLetter = currentLetter // see defer block | ||
return true | ||
} | ||
//previousLetter = currentLetter // see defer block | ||
return false | ||
} | ||
func insertSpaceAtCamelcase(inString:String)->String{ | ||
|
||
func insertSpaceAtCamelcase(_ inString: String) -> String { | ||
var accumulate = "" | ||
var lastIndexAdded = 0 | ||
for (index , each) in inString.characters.map({String($0)}).enumerate() { | ||
if splitCamelcaseAt(each, withString: &previousLetter){ | ||
|
||
for (index, each) in inString.characters.map({String($0)}).enumerated() { | ||
if splitCamelcaseAt(each, withString: &previousLetter) { | ||
accumulate += inString.substringWithRangeInt(start: lastIndexAdded, end: index)+" " // inserts a space | ||
lastIndexAdded = index | ||
} | ||
} | ||
let lastStringSection = inString.substringWithRangeInt(start: lastIndexAdded, end: inString.characters.count) | ||
return accumulate + lastStringSection | ||
} | ||
func splitAt(characterToCompare:Character, charToSplitAt:String = " ,-:")-> Bool{ | ||
for each in charToSplitAt.characters{ | ||
if each == characterToCompare{ | ||
|
||
func splitAt(_ characterToCompare: Character, charToSplitAt: String = " ,-:") -> Bool { | ||
for each in charToSplitAt.characters { | ||
if each == characterToCompare { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
func splitStringToArray(inString:String) -> [String]{ | ||
return inString.characters.split(isSeparator: { splitAt($0) }).map{String($0)} | ||
|
||
func splitStringToArray(_ inString: String) -> [String] { | ||
|
||
return inString.characters.split(isSeparator: { splitAt($0) }).map {String($0)} | ||
} | ||
|
||
return splitStringToArray(insertSpaceAtCamelcase(inString)).map({$0.uppercaseString.substringWithRangeInt(start: 0, end: 1)}).joinWithSeparator("") | ||
} | ||
|
||
} | ||
|
||
return splitStringToArray(insertSpaceAtCamelcase(inString)).map({$0.uppercased().substringWithRangeInt(start: 0, end: 1)}).joined(separator: "") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,31 @@ | ||
|
||
import XCTest | ||
|
||
|
||
#if swift(>=3.0) | ||
import XCTest | ||
#endif | ||
|
||
class AcronymTest: XCTestCase { | ||
func testAcronymAbbreviateTest1(){ | ||
|
||
func testAcronymAbbreviateTest1() { | ||
XCTAssertEqual("PNG", Acronym.abbreviate("Portable Network Graphics")) | ||
} | ||
func testAcronymAbbreviateTest2(){ | ||
|
||
func testAcronymAbbreviateTest2() { | ||
XCTAssertEqual("ROR", Acronym.abbreviate("Ruby on Rails")) | ||
} | ||
func testAcronymAbbreviateTest3(){ | ||
|
||
func testAcronymAbbreviateTest3() { | ||
XCTAssertEqual("HTML", Acronym.abbreviate("HyperText Markup Language")) | ||
} | ||
func testAcronymAbbreviateTest4(){ | ||
|
||
func testAcronymAbbreviateTest4() { | ||
XCTAssertEqual("FIFO", Acronym.abbreviate("First In, First Out")) | ||
} | ||
func testAcronymAbbreviateTest5(){ | ||
|
||
func testAcronymAbbreviateTest5() { | ||
XCTAssertEqual("PHP", Acronym.abbreviate("PHP: Hypertext Preprocessor")) | ||
} | ||
func testAcronymAbbreviateTest6(){ | ||
|
||
func testAcronymAbbreviateTest6() { | ||
XCTAssertEqual("CMOS", Acronym.abbreviate("Complementary metal-oxide semiconductor")) | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.