Skip to content

Instantly share code, notes, and snippets.

@mingsai
Created February 7, 2017 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mingsai/6d510cd58deb8a703941fa0214861f90 to your computer and use it in GitHub Desktop.
Save mingsai/6d510cd58deb8a703941fa0214861f90 to your computer and use it in GitHub Desktop.
Swift Playground Code for Reflection (Swift 3.0.1)
//: 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