Created
February 7, 2017 20:50
-
-
Save mingsai/6d510cd58deb8a703941fa0214861f90 to your computer and use it in GitHub Desktop.
Swift Playground Code for Reflection (Swift 3.0.1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
var str = "Mirror playground Swift 3.0.1" | |
struct User { | |
var givenName:String | |
var familyName:String | |
var loginName:String | |
var primaryEmail:String | |
var socialAccount:String | |
var password:String | |
} | |
let muser = Mirror(reflecting: User(givenName:"Tommie",familyName:"Carter", loginName:"mingsai", primaryEmail:"tcarternyc@gmail.com",socialAccount:"gmail",password:"adumbpassword")) | |
let numChildren = muser.children | |
var info:[AnyHashable:Any] = [:] | |
muser.children.forEach { (child) in | |
info.updateValue(child.value, forKey: child.label!) | |
print(child.label!, child.value) | |
} | |
print (info) | |
let count = numChildren.count | |
muser.displayStyle | |
muser.subjectType | |
muser.customMirror | |
muser.superclassMirror | |
print(numChildren) | |
print(muser) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment