I want to add a generic parameter for all collection type that has isEmpty
so they can also have isNotEmpty
When I try to make Collection
conform to Occupiable
I got an compile error
error here : Extension of protocol 'Collection' cannot have an inheritance clause
also String
conform to a protocol that inherent from Array so can we just remove extension String: Occupiable { }
once we found a solution for the issue above ?
// Anything that can hold a value (strings, arrays, etc)
protocol Occupiable {
var isEmpty: Bool { get }
var isNotEmpty: Bool { get }
}
// Give a default implementation of isNotEmpty, so conformance only requires one implementation
extension Occupiable {
var isNotEmpty: Bool {
return !isEmpty
}
}
extension String: Occupiable { }
// error here : Extension of protocol 'Collection'
// cannot have an inheritance clause
extension Collection: Occupiable { }