Latest 1.0.2
Homepage https://github.com/adela-chang/StringExtensionHTML
License MIT
Platforms ios 8.0, requires ARC
Authors

CI Status
Version
License
Platform

Usage

This string extension provides two main methods, stringByDecodingHTMLEntities and stringByStrippingHTMLTags.

import StringExtensionHTML

var text = ""some html string with entities ""
let decodedText = text.stringByDecodingHTMLEntities

var text = "<span><p>Some text full of <i>unwanted</i> html tags</p></span>
let decodedText = text.stringByStrippingHTMLTags

Sample Project

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

StringExtensionHTML is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'StringExtensionHTML'

The latest pod works with Swift 4. For the Swift 3 version, add the following line:

pod 'StringExtensionHTML', '~> 0.2'

For the Swift 2 version, add the following line:

pod 'StringExtensionHTML', '~> 0.1'

Alternatively, copy StringExtensionHTML.swift and add that single file into your Swift project. If you use this method, you can omit the line "import StringExtensionHTML" at the top of your file.

Credits

Original solution and former adaptations credit to Michael Waterfall and Martin from the Stack Overflow thread How do I decode HTML entities in swift?. I upgraded to work with Swift 2.0 and made it available through CocoaPods.

Note: there is a Swift 2 version by Santiago in the original thread’s comments. However, while that version will compile, it will not handle numeric character entities properly and also has some flaws which will cause it to crash anytime it comes to an entity it doesn’t understand.

Author

Adela Chang, [email protected]

License

StringExtensionHTML is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "StringExtensionHTML",
    "version": "1.0.2",
    "summary": "Extends the native Swift string with a method to easily decode HTML entities.",
    "description": "Extends the Swift native string with methods to quickly and easily decode any HTML entities that might be in the string.",
    "homepage": "https://github.com/adela-chang/StringExtensionHTML",
    "license": "MIT",
    "authors": {
        "Adela": "[email protected]"
    },
    "source": {
        "git": "https://github.com/adela-chang/StringExtensionHTML.git",
        "tag": "1.0.2"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*"
}

Pin It on Pinterest

Share This