Created
June 24, 2016 06:41
-
-
Save tanabee/3326172e7664bf01990a11190343c88a to your computer and use it in GitHub Desktop.
カスタムオブジェクトの print を key: value 形式で吐かせる
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
import UIKit | |
class CustomObject: NSObject { | |
override var description: String { | |
let mirror = Mirror(reflecting: self) | |
return mirror.children.map { (element) -> String in | |
let key = element.label ?? "Undefined" | |
let value = element.value | |
if value is CustomObject || value is NSArray { | |
return "\(key): \(value.dynamicType)" | |
} else { | |
return "\(key): \(value)" | |
} | |
}.joinWithSeparator("\n") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment