Skip to content

Instantly share code, notes, and snippets.

@ezura
Last active December 20, 2015 12:00
Show Gist options
  • Save ezura/aa289aaddbffc71bd5d4 to your computer and use it in GitHub Desktop.
Save ezura/aa289aaddbffc71bd5d4 to your computer and use it in GitHub Desktop.
自作クラス、構造体の \(), print() をカスタマイズする ref: http://qiita.com/ezura/items/8f31b14bd1418a0dab81
class DescriptionSample: Printable, DebugPrintable {
var m = "sample"
// Printable
var description: String {
return "\(m) description"
}
// DebugPrintable
var debugDescription: String {
return "\(m) debugDescription"
}
}
let b = DescriptionSample()
print(b) // "sample description\n"
debugPrint(b) // "sample debugDescription\n"
"\(b)" // "sample description"
class NormalClass {
var m = "sample"
}
let a = NormalClass()
print(a) // NormalClass\n
debugPrint(a) // NormalClass\n
"\(a)" // "NormalClass"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment