Swift: Extending functionality of print() function

前端 未结 3 757
甜味超标
甜味超标 2020-12-09 05:01

Is it possible to extend the functionality of a Swift function? I would like appnd a single character onto every print() function in my program without having to create a br

3条回答
  •  孤城傲影
    2020-12-09 05:26

    This code working for me in swift 3

    import Foundation
    
    public func print(_ items: Any..., separator: String = " ", terminator: String = "\n") {
        let output = items.map { "\($0)" }.joined(separator: separator)
        Swift.print(output, terminator: terminator)
    }
    
    class YourViewController: UIViewController {
    }
    

提交回复
热议问题