Latest 0.2.1
Homepage https://github.com/iosdevzone/Emarcam
License MIT
Platforms ios 9.0, osx 10.11
Authors

Getting started

Assuming you have integrated Emarcam into your project using your preferred method (CococaPods, Carthage, Swift Package Manager or manually), just import the module at the top of your file.

import Emarcam

Subscripting

Emarcam greatly simplifies subscripting strings by allowing you to use Ints as indices. For example:

let str = "Hello, playground!"
str[0] // "H"
str[1] // "e"
str[0..<4] // "Hell"
str[0...4] // "Hello"
str[6..<str.count] // " playground!"

Compare this to the same expressions in Swift 4.

str[str.startIndex]
str[str.index(after: str.startIndex)]
str[str.startIndex..<str.index(str.startIndex, offsetBy:4)]
str[str.startIndex...str.index(str.startIndex, offsetBy:4)]
str[str.index(str.startIndex, offsetBy:6)..<str.endIndex]

Replacing Substrings

The same simplified integer ranges can be used in the replacement methods. Here the Kanji ‘休’ is replaced with its pronunciation ‘やす’.

var ms0 = "お休みなさい"
let hiragana: [Character] = [ "や", "す" ]
ms0.replaceSubrange(1..<2, with: hiragana)
// おやすみなさい

Removing Substrings

Removal of substrings is also a happier experience.

var ms1 = "😭☠️☠️😀💀😀☠️☠️😡"
ms1.removeSubrange(0...2)          // ms1 = "😀💀😀☠️☠️😡"
ms1.remove(at: 1)                  // returns '💀' and ms1 = "😀😀☠️☠️😡"
ms1.removeSubrange(2..<ms1.count)  // ms1 = ""😀😀"

Latest podspec

{
    "name": "Emarcam",
    "version": "0.2.1",
    "summary": "An attempt to undo some of the knots in Swift `String`s.",
    "description": "Emarcam provides a simplified API for Swift strings. Essentially it allows the use of plain old integer ranges anywhere that the Stnadard library expects a `Range`.",
    "homepage": "https://github.com/iosdevzone/Emarcam",
    "license": "MIT",
    "authors": {
        "idz": "[email protected]"
    },
    "social_media_url": "https://twitter.com/iosdevzone",
    "platforms": {
        "ios": "9.0",
        "osx": "10.11"
    },
    "source": {
        "git": "https://github.com/iosdevzone/Emarcam.git",
        "tag": "0.2.1"
    },
    "source_files": "Sources/*.swift",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This