 // 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)
     }
 }
 

// String extensions for being forgiving of different styles of string representation and capitalization

extension String {
    func isVariantOf(string:String) -> Bool {
        let components = string.componentsSeparatedByString(" ")
        return self == string  //"Example Test String"
            || self == string.lowercaseString //"example test string"
            || self == string.lowercaseString.stringByReplacingOccurrencesOfString(" ", withString: "") //"exampleteststring"
            || self == string.stringByReplacingOccurrencesOfString(" ", withString: "") //"ExampleTestString"
            || self == string.lowercaseString.stringByReplacingOccurrencesOfString(" ", withString: "-") //"example-test-string
            || self == string.lowercaseString.stringByReplacingOccurrencesOfString(" ", withString: "_") //"example_test_string
            || self == (components.count > 1 ? components.first!.lowercaseString + components[1..<components.count].flatMap{$0.capitalizedString}.joinWithSeparator("") : string) //"exampleTestString"
            || self.lowercaseString.stringByReplacingOccurrencesOfString(" ", withString: "") == string.lowercaseString.stringByReplacingOccurrencesOfString(" ", withString: "") //"EXample String" != "Example String" -> "examplestring" == "examplestring"
    }
}

private class BundleMarker {}



// MARK - StylePropertySet -

// A style property set is a way of organizing sets of properties that can be style by the type of iew they apple to.  For example, you may want a "tint" property on a custom class, which should not be confused with "tintColor" on a UIView.  The style property sets separate out the properties into logicial groupings, e.g. 'style.CustomView.tint' vs. 'style.UIView.tintColor'

protocol StylePropertySet {
    init()

            return
        }
        for type in parameterSets {
            dictionary[String(describing: type)] = type.init()
        }
    }
    
    convenience init(asCopyOf:StylePropertySetCollection) {
        self.init()
        self.dictionary = asCopyOf.dictionary
    }
}

