0

I wish to create an array which will only hold unique instances of a struct:

  var vowelSet: Set<NotificationStruct> 

Here is my struct:

struct NotificationStruct{
    let dateHeader: String
    let sensorName: String
    let message: String
    let time: String
}

yet I keep getting the error: "does not conform to protocol 'Hashable'" here is what I tried:

 struct NotificationStruct<T: Hashable>{
Hamish
  • 78,605
  • 19
  • 187
  • 280
fred shmed
  • 77
  • 2
  • 6
  • 1
    `struct NotificationStruct: Hashable`, implement the required methods, or wait for Swift 4.1 to have them implemented by compiler :) – Cristik Mar 02 '18 at 16:44
  • You are asking for an array, but you are creating a Set... – Ahmad F Mar 02 '18 at 16:44
  • well, I can settle for an Set – fred shmed Mar 02 '18 at 16:46
  • Gah! I hate when I waste time on an answer only to have the question deleted or closed out from under me before I can post it ... If you need a `Set` of unique values, see here: https://developer.apple.com/documentation/swift/hashable – mc01 Mar 02 '18 at 16:58

1 Answers1

0

In the original question you are saying an array but creating a Set. Do you need something like this:

struct NotificationStruct {
    let sensorName :String
    let message :String
}

var vowelsArray = [NotificationStruct]() 
azamsharp
  • 19,710
  • 36
  • 144
  • 222