Skip to content

muzcity/MZVariant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MZVariant

CI Status Version License Platform

Example

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

Requirements

Installation

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

pod "MZVariant"

Usage

// used for basic type
var variant = MZVariant("1234")
let variant1 = MZVariant(98765)

if let value = variant.value(type: String.self) {
    print("\(value)")
}

if let value = variant1.value(type: Int.self) {
    print("\(value)")
}

print("\(variant.setValue(value: "5555"))")

// type check function.
if variant.isIncludedType(value: Int.self) {
    print("inner type is Int")
}
else {
    print("inner type is other")
}

if variant.isIncludedType(value: String.self) {
    print("inner type is String")
}
else {
    print("inner type is other")
}

// used for class
let c = SomeClass()
let variant2 = MZVariant(c)

if let value = variant2.value(type: SomeClass.self) {
    print("\(value.num)")
}


// used for dictionary
var dictionary : [String:MZVariant] = [:]

dictionary["key"] = MZVariant("mzvariant value")
dictionary["key1"] = MZVariant(123.4567)


if let value = dictionary["key"]?.value(type: String.self) {
    print("\(value)")
}

if let value = dictionary["key1"]?.value(type: Double.self) {
    print("\(value)")
}

Author

muzcity@gmail.com

License

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