forked from bestswifter/MySampleCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebug.swift
More file actions
47 lines (40 loc) · 1.01 KB
/
Debug.swift
File metadata and controls
47 lines (40 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//
// Debug.swift
// Streamable
//
// Created by 张星宇 on 16/1/26.
// Copyright © 2016年 zxy. All rights reserved.
//
import Foundation
struct PersonDebug {
var name: String
private var age: Int
init(name: String, age: Int) {
self.name = name
self.age = age
}
}
extension PersonDebug: CustomStringConvertible, CustomDebugStringConvertible {
var description: String {
return "In CustomStringConvertible Protocol"
}
var debugDescription: String {
return "In CustomDebugStringConvertible Protocol"
}
}
// print优先调用CustomStringConvertible
func testCustomStringConvertible() {
print("print结构体")
let kt = PersonDebug(name: "kt", age: 21)
print(kt)
print(String(kt))
print("")
}
// debugPrint优先调用CustomDebugStringConvertible
func testCustomDebugStringConvertible() {
print("debugPrint结构体")
let kt = PersonDebug(name: "kt", age: 21)
debugPrint(kt)
print(String(reflecting: kt))
print("")
}