๐log()
๐พ ็จๅผ๏ผ replit โฌ๏ธ ้่ฆ๏ผ HasMirrors
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// 2022.01.27 * (v.1) + log()
// 2022.01.28 / log() use Logger instead
// 2022.01.30 + log() + param `items: [HasMirrors]`
// / log(_ item:) delegate to `HasMirrors` method
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// โญ require `HasMirrors`
/// `log(msg)`
public func log(_ item: HasMirrors) {
_ = item.log()
}
/// `log(items)`
/// โญ benefit:
/// - needn't declare `items` as `HasMirrors`,
/// compiler will infer it.
public func log(_ items: [HasMirrors]) {
items.log()
}
๐พ ็จๅผ๏ผ replit
// log(item)
log(true)
log(1.23)
// log(items)
log([
123, "string", 1.23, true,
])
Result:
// โ
// ๐ 1.23
// ๐ 123
// ๐ string
// ๐ 1.23
// โ
Swift Ref โฉ Expressions โฉ Primary Expressions โฉ Literal Expression
Macros in Swift? - custom log function using #file, #line, #function โญ๏ธ
uses HasMirrors.
.logType() - inspect a view's type.
History
(2022.01.27) - first version
(2022.01.28) - use Logger.
๐พ ็จๅผ๏ผ replit
// ----------------------
// โญ log function
// ----------------------
func log(
_ message: String = "",
file : String = #file, // โญ file name
line : Int = #line, // โญ line number
function : String = #function, // โญ function name
note : String? = nil // additional info
) {
let noteString = (note == nil) ? "" : "\n \(note!)"
print("\n๐ \(message)\n ( func: '\(function)', line: \(line), file: '\(file)' )\(noteString)")
}
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// 2022.01.27 * (v.1)
// 2022.01.28 / use Logger instead
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
/// `log(msg)`
public func log(
_ message: String = "",
padding n: Int = 0,
dot : String? = nil
) {
Logger.log(message, padding: n, dot: dot)
}
Last updated