I'm very new to Swift/iOS programming, but something like this works for me.
func fetchDepRefs() -> Array<Datable> {return Array<Datable>()}
var depRefList = fetchDepRefs()
var testDEPref = DEPref(date: NSDate())
var testDEPref2 = DEPref(date: NSDate())
depRefList.append(testDEPref)
depRefList.append(testDEPref2)
for ref in depRefList {
print(ref.date)
}
Your functions could also return [Datable]
eg.
func fetchDepRefs() -> [Datable] {return [Datable]()}
This also works for your scenario
Edit:
Or if you're looking for type safety in your functions, the following code will also work
func fetchDepRefs() -> [DEPref] {return [DEPref]()}
func fetchDepObss() -> [DEPObs] {return [DEPObs]()}
var depRefList = fetchDepRefs()
var depObsList = fetchDepObss()
var allDeps: [Datable] = [Datable]()
In this you can add elements from depRefList and depObsList to allDeps and everything will work fine.
Edit again:
This is a fully working example of what you're trying to achieve. In this I'm using the map function to transform the elements of the given arrays to Datable objects
protocol Datable {
var date: NSDate { get set }
}
struct DEPref: Datable {
var date: NSDate
}
struct DEPObs: Datable {
var date: NSDate
}
func fetchDepRefs() -> [DEPref] {return [DEPref]()}
func fetchDepObs() -> [DEPObs] {return [DEPObs]()}
var depRefs = fetchDepRefs()
var depObs = fetchDepObs()
var ref1 = DEPref(date: NSDate())
var obs1 = DEPObs(date: NSDate())
depRefs.append(ref1)
depObs.append(obs1)
var allDeps = depRefs.map{$0 as Datable} + depObs.map{$0 as Datable}
for x in allDeps {
print("I'm in allDeps array: \(x.date)")
}