在Swift3.0中获取错误:
二元运算符' +'不能应用于' [FutureTrainee]'和' [FutureTrainee]?'
代码:
height: 200px
答案 0 :(得分:0)
正如错误所示,您无法使用+
添加[FutureTrainee]
(又名Array<FutureTrainee>
)和[FutureTrainee]?
(又名Optional<Array<FutureTrainee>>
。
newTrainees
的类型为[FutureTrainee]?
,因为您使用data
下标"data"
的可选链接。这段代码:
let newTrainees = data?["data"].arrayValue.map({ (json) in
return FutureTrainee(data: json)
})
就像:
var newTrainees: [FutureTrainee]?
if let data = data {
newTrainees = data["data"].arrayValue.map({ (json) in
return FutureTrainee(data: json)
})
else {
newTrainees = nil
}
如果newTrainees
不为零,您需要确保只附加var trainees = self.futureTraineeCollection
if let newTrainees = data?["data"].arrayValue.map{ FutureTrainee(data: $0) } {
// If that expression is not nil, the result is bound to "newTrainees"
trainees += newTrainees
}
,如下所示:
Name: r_DTS, dtype: category
Categories (4, object): [Bottom < 2 < Top < Missing]