0
에 배열 사전 값을 대체 어떻게 내 배열은 내가 찾아 바꾸려는이 사전을이 곳 사전 시간 출석 = ""출석 = "A"와 출석 대체 = "P"우리가 발견하고 신속한 3
구조체/클래스 모델을 만들고 이러한 개체 및 속성을 사용하는 대신 사전을 사용하여 :나는 이것을 사용하고 있습니다 :
checkedArray = [[String : AnyObject]]()
let index = find(checkedArray) { $0["attendance"] == "P" }
if let index = index {
checkedArray[index] = newDictionary
}
// Do any additional setup after loading the view.
}
func find<C: CollectionType>(collection: C, predicate: (C.Generator.Element) -> Bool) -> C.Index? {
for index in collection.startIndex ..< collection.endIndex {
if predicate(collection[index]) {
return index
}
}
return nil
}
[
{"studentID":"12","name":"panky","roll":"","attendance":"P"},
{"studentID":"14","name":"a","roll":"","attendance":""},
{"studentID":"4","name":"akshay","roll":"1","attendance":"E"},
{"studentID":"6","name":"anki","roll":"11","attendance":"P"},
{"studentID":"1","name":"mohit","roll":"2","attendance":"M"},
{"studentID":"5","name":"yogi","roll":"22","attendance":"L"},
{"studentID":"3","name":"Neha","roll":"3","attendance":"A"}
]
팁. – Moritz