ios - Set of protocols in Swift -


having set of specific interface in java useful:

hashset<myinterface> myset; 

is possible similar in swift?

i tried unsuccessfully following:

public protocol dialogdelegate : class, hashable {     func myfunction() }  public final class dialogmanager: nsobject {     private var _dialogdelegates: set<dialogdelegate>      private override init()     {         _dialogdelegates = set<dialogdelegate>()         super.init();     } } 

i compiler error:

protocol 'dialogdelegate' can used generic constraint because has self or associated type requirements

the problem you're having explained in: what "protocol ... can used generic constraint because has self or associated type requirements" mean?

to solve use dialogdelegate generic type constraint:

public final class dialogmanager<t: dialogdelegate>: nsobject {     private var _dialogdelegates: set<t>      private override init()     {         _dialogdelegates = set<t>()         super.init();     } } 

bear in mind, won't allow allowed mix types of objects stored in _dialogdelegates; may or may not problem you.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -