I am trying to populate a table with sections and rows based off array slices. I keep getting " Cannot invoke initializer for type "Objects" with and argument list of type'(sectionName: String, sectionObjects: ArraySlice). Wondering if anyone could shed some light on what I am Missing. Thanks.
https://app.smartsheet.com/b/authorize
答案 0 :(得分:1)
您可以使用Array(ArraySlice)
这是您更新的代码:
func test(){
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = " eee, MMM dd, yyyy "
let today = (NSDate())
let comps : NSCalendarUnit = NSCalendarUnit.Day
let cal = NSCalendar.currentCalendar()
let todaysDate = cal.startOfDayForDate(today)
var dates = [String]()
var displayMe = [String]()
for i in 0 ... 179 {
let day = dateFormatter.stringFromDate(cal.dateByAddingUnit(comps, value: +i, toDate: todaysDate, options: [] )!)
dates += [day]
}
for (index, value) in dates.enumerate() {
let testMe = ("Day \(index + 1) - \( value)")
print(testMe)
displayMe += [testMe]
}
let datesOneRange = displayMe[0...13]
let datesFifteenRange = displayMe[14...28]
let datesThrityRange = displayMe[29...58]
let datesSixtyRange = displayMe[59...88]
let datesNinetyRange = displayMe[89...99]
let datesOneHunEighty = displayMe[100...179]
let dateDict = [ " 5 Days" : datesOneRange,
" 14 Days" : datesFifteenRange,
" 30 Days" : datesThrityRange,
" 60 Days" : datesSixtyRange,
" 90 Days" : datesNinetyRange,
"180 Days" : datesOneHunEighty]
struct Objects {
var sectionName : String!
var sectionObjects : [String]!
}
var objectArray = [Objects]()
for (key, value) in dateDict {
print("\(key) -> \(value)")
objectArray.append(Objects(sectionName: key, sectionObjects:Array(value)))
}
}