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