Swift version of Stringattribute

Source: Internet
Author: User

Swift version of Stringattribute

Effect

Source

Https://github.com/YouXianMing/Swift-StringAttribute

////Stringattributeprotocol.swift//Swift-stringattribute////Created by youxianming on 15/10/8.//copyright©2015 year youxianming. All rights reserved.//Import FOUNDATION@OBJC protocol Stringattributeprotocol {/** Rich Text attribute name-Returns: attribute name*/func attributename ()-NSString; /** attribute corresponding to the value-returns: corresponding value*/func attributevalue ()-Anyobject; /** Attribute set effective range-Returns: Effective range*/optional func effectivestringrange ()-Nsrange;}
////Stringattribute.swift//Swift-stringattribute////Created by youxianming on 15/10/8.//copyright©2015 year youxianming. All rights reserved.//Import UIKitclassStringattribute:nsobject, Stringattributeprotocol {//MARK: Common Properties        ///Rich Text effective rangevar effectrange:nsrange! = Nsmakerange (0,0)        //MARK: A common approach        /** Attribute Valid range-Returns: Valid range*/func effectivestringrange ()-Nsrange {returnEffectrange}//MARK: = = Method overridden by subclass = =        /**/////////////////overriding/////////////////property name-Returns: attribute name*/func attributename ()-nsstring {fatalerror ("must is overwrote by subclass")    }        /**/////////////////overriding/////////////////property value-Returns: Property value*/func attributevalue ()-anyobject {fatalerror ("must is overwrote by subclass")    }}
////Nsmutableattributedstring+stringattribute.swift//Swift-stringattribute////Created by youxianming on 15/10/8.//copyright©2015 year youxianming. All rights reserved.//Import foundationextension nsmutableattributedstring {/** Add Rich Text Object-parameter Stringattribute: Object that implements the Stringattributeprotocol protocol*/func Addstringattribute (stringattribute:stringattributeprotocol) {Self.addattribute (stringattribute. AttributeName () asString, Value:stringAttribute.attributeValue (), range:stringattribute.effectivestringrange!())    }        /** Eliminate the specified Rich text object-parameter Stringattribute: Object that implements the Stringattributeprotocol protocol*/func Removestringattribute (stringattribute:stringattributeprotocol) {Self.removeattribute (stringAttr Ibute.attributename () asString, Range:stringAttribute.effectiveStringRange!())    }}

Analysis

Swift version of Stringattribute

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.