let chapterPath = NSBundle.mainBundle().pathForResource("chapterMapping", ofType: "plist") if let arrayOfItems: [AnyObject] = NSArray(contentsOfFile: chapterPath!) { let chapterNames: [String] = arrayOfItems.valueForKeyPath("chapterName") as NSArray as [String] let pageNumbers: [Int] = arrayOfItems.valueForKeyPath("pageNumber") as NSArray as [Int] }
第三,做这件事的 swift y 方式会与 map 功能,但 arrayOfItems 将需要一个强烈定义的类型,它可能更多的工作,真不值得。 示例:
let array: [ChapterMetaData] = // define it here let chapterImages = array.map { $0.chapterImage }