Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tanabee
Created June 24, 2016 06:41
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 tanabee/3326172e7664bf01990a11190343c88a to your computer and use it in GitHub Desktop.
Save tanabee/3326172e7664bf01990a11190343c88a to your computer and use it in GitHub Desktop.
カスタムオブジェクトの print を key: value 形式で吐かせる
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