Swift NSCountedSet init with array bug?

前端 未结 1 1648
暗喜
暗喜 2021-01-11 23:25

There seems to be a bug in Swift Playground with the use of NSCountedSet.

This code works as intended

let numbers = [1,2,2,4,6,7,8,8,5,8,1]

let set          


        
1条回答
  •  孤街浪徒
    2021-01-11 23:58

    Update: As @carbo18 reported, this has been fixed in Xcode 6.3 beta 4.

    Old answer: That definitely looks like a bug. NSCountedSet has initializers

    convenience init(array: [AnyObject])
    convenience init(set: NSSet)
    

    but

    let b1 = NSCountedSet(array: [])     // extra argument 'array' in call
    let b2 = NSCountedSet(set: NSSet())  // extra argument 'set' in call
    

    both fail to compile.

    This was also reported in the Apple Developer Forum (https://devforums.apple.com/message/1081850#1081850), where the following workaround is given:

    let numbers = [1,2,2,4,6,7,8,8,5,8,1]
    let bag = NSCountedSet()
    bag.addObjectsFromArray(numbers)
    

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