 // Retrieve a specific StylePropertySet by name or by type
 extension StyleClass {
     mutating func register(propertySet:StylePropertySet) {
-        stylePropertySets.register(propertySet)
+        if isKnownUniquelyReferenced(&stylePropertySets) {
+            stylePropertySets.register(propertySet: propertySet)
+        } else {
+            stylePropertySets = StylePropertySetCollection(asCopyOf: stylePropertySets)
+            stylePropertySets.register(propertySet: propertySet)
+        }
     }
     func retrieve<T:StylePropertySet>(propertySet:T.Type)->T {
-        return stylePropertySets.retrieve(propertySet)
+        return stylePropertySets.retrieve(propertySetType: propertySet)
     }
     func retrieve(dynamicPropertySetName:String)->DynamicStylePropertySet? {
-        return stylePropertySets.retrieve(dynamicPropertySetName)
+        return stylePropertySets.retrieve(dynamicPropertySetName: dynamicPropertySetName)
     }
 }
 

}


class StylePropertySetCollection {
    
    private var dictionary = [String : StylePropertySet]()
    
    private func retrieve<T:StylePropertySet>(propertySetType:T.Type) -> T {
        if let existing = dictionary[String(propertySetType)] as? T {
            return existing
        }
        dictionary[String(propertySetType)] = T.init()
        return dictionary[String(propertySetType)] as! T
    }
    
    private func retrieve(dynamicPropertySetName:String)->DynamicStylePropertySet? {
        return dictionary[dynamicPropertySetName] as? DynamicStylePropertySet
    }
    
    private func register(propertySet:StylePropertySet) {
        dictionary[String(propertySet.dynamicType)] = propertySet
    }
    
    // Optional: the collection can be initialized prepopulated with property sets.  This is only needed if using dynamic / string based lookup

    var text:String?
    var highlighted:Bool?
    var highlightedTextColor:UIColor?
    var customUILabelStyleBlock:((UILabel)->())?
    mutating func setStyleProperty<T>(named name: String, toValue value: T) {
        switch name {
        case _ where name.isVariant(of: "Text Color"):
            textColor = value as? UIColor
        case _ where name.isVariant(of: "Font"):
            font = value as? UIFont
        case _ where name.isVariant(of: "Enabled"):
            enabled = value as? Bool
        case _ where name.isVariant(of: "Text Alignment"):
            textAlignment = value as? NSTextAlignment
        case _ where name.isVariant(of: "Text"):
            text = value as? String
        case _ where name.isVariant(of: "Highlighted"):
            highlighted = value as? Bool
        case _ where name.isVariant(of: "Highlighted Text Color"):
            highlightedTextColor = value as? UIColor
        default :
            return
