Can you use map to create instances without a wrapper?

后端 未结 3 1470
半阙折子戏
半阙折子戏 2021-01-21 01:56

In Python, you can give the name of a class as an argument to map in order to create instances of that class:

class Point(object):
    def __init__(         


        
3条回答
  •  庸人自扰
    2021-01-21 02:35

    This is now possible in Xcode 7.0 beta 2

    from the release notes

    Initializers can now be referenced like static methods by referring to .init on a static type reference or type object:

      let x = String.init(5)
      let stringType = String.self
      let y = stringType.init(5)
      let oneTwoThree = [1, 2, 3].map(String.init).reduce(“”, combine: +)
    

提交回复
热议问题