-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlavorFactory.swift
37 lines (26 loc) · 947 Bytes
/
FlavorFactory.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
// FlavorFactory.swift
// IceCreamShop
//
// Created by Joshua Greene on 2/9/15.
// Copyright (c) 2015 Razeware, LLC. All rights reserved.
//
import Foundation
class FlavorFactory {
func flavorsFromPlistNamed(plistName: String, bundle: NSBundle = NSBundle.mainBundle()) -> [Flavor] {
let path = bundle.pathForResource(plistName, ofType: "plist")!
let data = NSData(contentsOfFile: path)!
let options = NSPropertyListMutabilityOptions.Immutable;
let array = try! NSPropertyListSerialization.propertyListWithData(data, options: options, format: nil) as! [[String: String]]
return flavorsFromDictionaryArray(array)
}
func flavorsFromDictionaryArray(array: [[String: String]]) -> [Flavor] {
var flavors: [Flavor] = []
for dictionary in array {
if let flavor = Flavor(dictionary: dictionary) {
flavors.append(flavor)
}
}
return flavors
}
}