Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nvzqz/Roman
Seamless Roman numeral conversion in Swift
https://github.com/nvzqz/Roman
Last synced: about 2 months ago
JSON representation
Seamless Roman numeral conversion in Swift
- Host: GitHub
- URL: https://github.com/nvzqz/Roman
- Owner: nvzqz
- License: other
- Created: 2016-01-19T06:15:52.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-11-02T06:27:06.000Z (about 7 years ago)
- Last Synced: 2024-11-23T01:35:38.283Z (2 months ago)
- Language: Swift
- Homepage:
- Size: 637 KB
- Stars: 36
- Watchers: 6
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-swift - Roman - Seamless Roman numeral conversion. (Libs / Text)
- awesome-ios-star - Roman - Seamless Roman numeral conversion in Swift. (Text / Other Testing)
- awesome-swift-cn - Roman - Seamless Roman numeral conversion in Swift. (Libs / Text)
- awesome-ios - Roman - Seamless Roman numeral conversion in Swift. (Text / Other Testing)
README
Installation
• Usage
• License
• DocumentationRoman is a Swift framework that allows for seamless Roman numeral conversion.
## Installation
### Compatibility:
- Platforms:
- OS X
- iOS
- watchOS
- tvOS
- Linux
- Language:
- Swift 2.1+### Install Using Swift Package Manager
The [Swift Package Manager](https://swift.org/package-manager/) is a
decentralized dependency manager for Swift.1. Add the project to your `Package.swift`.
```swift
import PackageDescriptionlet package = Package(
name: "MyAwesomeProject",
dependencies: [
.Package(url: "https://github.com/nvzqz/Roman.git",
majorVersion: 1)
]
)
```2. Import the Roman module.
```swift
import Roman
```### Install Using CocoaPods
[CocoaPods](https://cocoapods.org/) is a centralized dependency manager for
Objective-C and Swift. Go [here](https://guides.cocoapods.org/using/index.html)
to learn more.1. Add the project to your [Podfile](https://guides.cocoapods.org/using/the-podfile.html).
```ruby
use_frameworks!pod 'Roman', '~> 1.1.0'
```2. Run `pod install` and open the `.xcworkspace` file to launch Xcode.
3. Import the Roman framework.
```swift
import Roman
```### Install Using Carthage
[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency
manager for Objective-C and Swift.1. Add the project to your [Cartfile](https://github.com/Carthage/Carthage/blob/master/Documentation/Artifacts.md#cartfile).
```
github "nvzqz/Roman"
```2. Run `carthage update` and follow [the additional steps](https://github.com/Carthage/Carthage#getting-started)
in order to add Roman to your project.3. Import the Roman framework.
```swift
import Roman
```### Install Manually
Simply add the `Roman.swift` file into your project.
## Usage
### String
A Roman numeral string can be created from an instance of a type that conforms
to `IntegerType`.```swift
String(roman: 1478) // "MCDLXXVIII"
String(roman: 2743) // "MMDCCXLIII"
String(roman: 1226) // "MCCXXVI"
String(roman: 0) // nil
String(roman: -42) // nil
```### IntegerType
All types that conform to `IntegerType` can be initialized from a Roman numeral
string.The input string is case insensitive.
```swift
Int(roman: "III") // 3
Int(roman: "MIV") // 1004
Int(roman: "CdV") // 405
```Roman even supports irregular numerals that don't use a short form.
Each of the following evaluates to `true`:
```swift
Int(roman: "IV") == Int(roman: "IIII")
Int(roman: "XX") == Int(roman: "VVVV")
Int(roman: "CD") == Int(roman: "CCCC")
```Invalid strings return `nil`.
```swift
Int(roman: "hello") == nil
Int(roman: "IIIXX") == nil
Int(roman: "XYZ") == nil
```### FloatingPointType
All types that conform to `FloatingPointType` can be initialized from a Roman
numeral string.Creating instances from Roman numerals works the same way as with `IntegerType`.
## License
Roman is released under the [MIT License](https://opensource.org/licenses/MIT).
All assets are released under the Creative Commons [Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/)
and can be found in the [Assets](https://github.com/nvzqz/Roman/tree/master/Assets)
folder.