ブロックは以下のように定義されます
// Declare block ( optional )
typealias sorting = (([Schedule], [String]) -> [Schedule])?
var sortSchedule: sorting = { (schedules, sortDescription) in
var array = [Schedule]()
for string in sortDescription
{
for (index, schedule) in schedules.enumerate()
{
if string == schedule.startTime
{
array.append(schedule)
break
}
}
}
return array
}
いくつかの時点で、次のようにしてブロックを呼び出しています
let allSchedules = sortSchedule?(result, sortDescription())
for schedule in allSchedules // Xcode complains at here
{
..........
}
?
ブロックが存在するかどうかを確認したいので、使用しています。ただし、Xcode はfor
ループに対して不平を言います
value of optional type [Schedule]? not upwrapped, did you mean to use '!' or '?'?
ブロックの戻り値の型は、0 個または複数の項目を持つことができる配列であるため、その理由はわかりません。
xcodeが不平を言っている理由を知っている人はいますか?