私はjsonファイルを読み込んでいる拡張子を持っていますが、それは問題ではありません。問題は、コレクションビューメソッドでクラスの配列を更新することです。私は拡張子の内部配列の長さを印刷するとき、私はコレクションビューのデリゲートメソッドは、私は方法クラス内の配列を拡張子で更新するにはどうすればよいですか?
でクラスに行くとき、それは0extension JSON{
func findmultiple(viewclass: ViewController, @noescape predicate: JSON -> Bool) -> JSON? {
if predicate(self) {
return self
}
else {
if let subJSON = (dictionary?.map { $0.1 } ?? array) {
for json in subJSON {
if let foundJSON = json.findmultiple(viewclass, predicate: predicate) {
let shorten = foundJSON["html"].stringValue
let firstshort = shorten.componentsSeparatedByString(" ")
let secondshort = firstshort[1].componentsSeparatedByString("\r")
let classname = secondshort[0]
if(classname == "STUDY HALL (INSTRUCT)"){
print("skip")
}else{
viewclass.importClass.append(classname)
print("fsgsfg \(viewclass.importgrades.count)") //prints("STUDY HALL", "CHEMISTRY", "PHYSICS")
}
}
}
}
}
return nil
}
}
を印刷しているクラスの中にそれを印刷するとき、私は3を得るが、
class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource{
var importClass = [String]()
func parseJSON(json: JSON){
let predicate = {
(json: JSON) -> Bool in
if let jsonID = json["class"].string where jsonID == "sg-header-heading"{
return true
}
return false
}
var backclass = ViewController()
let foundJSON = json.findmultiple(backclass, predicate: predicate)
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: colcell = (collection.dequeueReusableCellWithReuseIdentifier("CELL", forIndexPath: indexPath) as? colcell)!
print(importClass) //prints []
cell.classtitle.text = importClass[indexPath.item] //crashes `index out of range`
}
あなたはCollectionViewのカウントを設定していますか? – PeejWeej
はい私はカウントを設定しています – johnson