美文网首页
swift 重载自定义操作符

swift 重载自定义操作符

作者: lotawei | 来源:发表于2019-06-24 09:59 被阅读0次

    关键字 infix operatore

    infix operator <-->//: AdditionPrecedence
    extension String {
     
        static func <-->(_ content: String, _ comment: String) -> String {
    
            return NSLocalizedString(content, comment: "")
        }
        
        func localization(_ comment: String? = nil) -> String {
            return NSLocalizedString(self, comment: comment ?? "")
        }
        
        /// 项目中采用这个方法简化NSLocalizedString方法
        var l: String {
            get {
                return NSLocalizedString(self, comment: "")
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:swift 重载自定义操作符

          本文链接:https://www.haomeiwen.com/subject/hhqnqctx.html