jonasman / MulticastDelegate

An elegant multicast delegate written in swift
MIT License
149 stars 28 forks source link

isEmpty is counting nil references #21

Closed RodolfoAntonici closed 5 years ago

RodolfoAntonici commented 5 years ago

As we can se in the issue #20, the delegates.count property will count nil references, which would cause the following implementation to fail:

public var isEmpty: Bool {
        return delegates.count == 0
}

To solve that:

public var isEmpty: Bool {
        return delegates.allObjects.count == 0
}

This will only count existing objects, nil references won't be indexed in the allObjects.

jonasman commented 5 years ago

Good finding!

from apple docs:

var allObjects: [ObjectType]
The hash table’s members.

var count: Int
The number of elements in the hash table.
jonasman commented 5 years ago

tag: 2.1.3