Implementing StringLiteralConvertible on NSURL

前端 未结 1 2000
臣服心动
臣服心动 2021-01-17 23:34

I\'ve implemented StringLiteralConvertible, which extends ExtendedGraphemeClusterLiteralConvertible. It looks like it wants me to implement that to

相关标签:
1条回答
  • 2021-01-18 00:21

    The problem is related to your extension not conforming to the protocol. If you CMD+Click on the StringLiteralConvertible protocol, to follow it to it's definition, you will find that the typealias StringLiteralType and typealias ExtendedGraphemeClusterLiteralType are set to String.

    That being said, you should modify your extension to the following:

    extension NSURL : StringLiteralConvertible {
    
       class func convertFromStringLiteral(value: String) -> Self
       {
                  //do what you were going to do
          return self()
       }
    
       class func convertFromExtendedGraphemeClusterLiteral(value: String) -> Self{
                  //do what you were going to do
          return self()
       }
    }
    

    Information about typealias is described in "The Swift Programming Language" book from pages 606-609, under the section Associated Types.

    0 讨论(0)
提交回复
热议问题