Last active
September 24, 2018 19:59
-
-
Save LazyClutch/16a3096538cd938c5b74 to your computer and use it in GitHub Desktop.
Swift Reflection
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
// The test code of Swift Reflection API: http://appventure.me/2015/10/24/swift-reflection-api-what-you-can-do/ | |
import UIKit | |
public class Store { | |
let storesToDisk: Bool = true | |
} | |
public class BookmarkStore: Store { | |
let itemCount: Int = 10 | |
} | |
public struct Bookmark { | |
enum Group { | |
case Tech | |
case News | |
} | |
private let store = { | |
return BookmarkStore() | |
}() | |
let title: String? | |
let url: NSURL | |
let keywords: [String] | |
let group: Group | |
} | |
let aBookmark = Bookmark(title: "Appventure", url: NSURL(string: "appventure.me")!, keywords: ["Swift", "iOS", "OSX"], group: .Tech) | |
let aMirror = Mirror(reflecting: aBookmark) | |
print(aMirror.displayStyle) | |
print(aMirror.subjectType) | |
for case let (label?, value) in aMirror.children { | |
print (label, value) | |
} | |
let closure = { (a: Int) -> Int in return a * 2 } | |
let bMirror = Mirror(reflecting: closure) | |
print(bMirror.displayStyle) | |
print(aMirror.subjectType) | |
print(Mirror(reflecting: 5).subjectType) | |
print(Mirror(reflecting: "test").subjectType) | |
print(Mirror(reflecting: NSNull()).subjectType) | |
let cMirror = Mirror(reflecting: aMirror) | |
print(cMirror.displayStyle) | |
print(cMirror.subjectType) | |
for case let (label?, value) in cMirror.children { | |
print (label, value) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment