Last active
December 20, 2015 12:00
-
-
Save ezura/aa289aaddbffc71bd5d4 to your computer and use it in GitHub Desktop.
自作クラス、構造体の \(), print() をカスタマイズする ref: http://qiita.com/ezura/items/8f31b14bd1418a0dab81
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
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" |
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
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