-2

Let say I have the following protocol :

protocol DataResponse { .... }

My question is, how can I make another protocol like the following? :

protocol AnotherProtocol { var data:[DataProtocol] { get } }

When I am trying to do the above in my Struct below, I get Type 'MyStruct' does not conform to protocol 'AnotherProtocol'

struct myStruct : AnotherProtocol {

  var data:[a struct implements DataProtocol] ...
}
Ryan
  • 2,167
  • 2
  • 28
  • 33
Bobj-C
  • 5,276
  • 9
  • 47
  • 83

2 Answers2

0

What do you want to realize?

protocol DataResponse {
}

protocol AnotherProtocol {
    var data:[DataResponse] { get }
}

struct myStruct : AnotherProtocol {
    var data:[DataResponse]
}

This code compiles.

katleta3000
  • 2,484
  • 1
  • 18
  • 23
0

Your code in your answer is not very clear so I don't know what you are trying to do, but that should works for you:

protocol DataProtocol {
}

protocol AnotherProtocol {
    var data:[DataProtocol] { get }
}

struct dataStruct : DataProtocol {
}

struct myStruct : AnotherProtocol {

    var data:[DataProtocol] {
        return [dataStruct()]
    }
}
Greg
  • 25,317
  • 6
  • 53
  • 62
  • what I want to do is `struct myStruct : AnotherProtocol { var data:[dataStruct] { return [dataStruct()] } } ` because I have a lot of structs implement `DataProtocol ` – Bobj-C Nov 30 '15 at 11:02