2014-09-21 1 views
6

Swift에서 NSFetchedResultcController 섹션의 객체 수를 얻으려면 어떻게해야합니까? 그런 다음 section를 전달할 수NSFetchedResultsController 섹션의 객체 수를 얻는 방법 Swift

if let s = self.fetchedResultsController?.sections as? [NSFetchedResultsSectionInfo] 

:

if let s = self.fetchedResultsController?.sections as? NSFetchedResultsSectionInfo { 

    } 

나에게 Cannot downcast from '[AnyObject]' to [email protected] protocol type NSFetchedResultsSectionInfo

var d = self.fetchedResultsController?.sections[section].numberOfObjects 

을주고있다 당신은 ArrayNSFetchedResultsSectionInfo의 객체에 self.fetchedResultsController?.sections 캐스팅 할 필요가 저에게 does not have member named 'subscript'

답변

11

을 제공합니다 ~까지 그는 첨자와 객체의 수를 얻을 :

if let s = self.fetchedResultsController?.sections as? [NSFetchedResultsSectionInfo] { 
    d = s[section].numberOfObjects 
} 
3

을 나는 마이크 S에 의해 현재 허용 대답은 생각 이전 스위프트 2.0

중동 위해 (스위프트 2.1)가 작동 중이면 다음

if let sections = fetchedResultsController?.sections { 
    return sections[section].numberOfObjects 
} else { 
    return 0 
} 
관련 문제