This repository has been archived by the owner on Mar 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from cennydavidsson/master
Added Charater extension
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 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
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,21 @@ | ||
// | ||
// Character.swift | ||
// ExSwift | ||
// | ||
// Created by Cenny Davidsson on 2014-12-08. | ||
// Copyright (c) 2014 pNre. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension Character { | ||
|
||
/** | ||
If the character represents an integer that fits into an Int, returns | ||
the corresponding integer. | ||
*/ | ||
public func toInt () -> Int? { | ||
return String(self).toInt() | ||
} | ||
|
||
} |
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,24 @@ | ||
// | ||
// ExSwiftCharacterTests.swift | ||
// ExSwift | ||
// | ||
// Created by Cenny Davidsson on 2014-12-09. | ||
// Copyright (c) 2014 pNre. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
|
||
|
||
class ExSwiftCharacterTests: XCTestCase { | ||
|
||
func testToInt () { | ||
|
||
if let int = Character("7").toInt() { | ||
XCTAssertEqual(int, 7) | ||
} else { | ||
XCTFail("Character(\"7\").toInt()") | ||
} | ||
} | ||
|
||
|
||
} |