Reputation: 23
I'am planing to use a couple of large arrays in my project and like to store the arrays in a separate file. is this possible? here is my main viewcontroller example with the array "gruppe" I like to have in a separate file:
import UIKit
class ViewController: UIViewController {
var gruppe = ["new york", "sydney", "paris"]
@IBAction func knopf(sender: UIButton) {
println(gruppe[0])
}
}
Upvotes: 0
Views: 660
Reputation: 22487
You could try something like:
// File 1
import UIKit
class ViewController: UIViewController {
@IBAction func knopf(sender: UIButton) {
println(DataClass.gruppe()[0])
}
}
// File 2
class DataClass {
class func gruppe() -> [String] {
return ["new york", "sydney", "paris"]
}
}
Upvotes: 1
Reputation: 89509
You can bridge a Swift array to a NSArray.
doing something like:
let cocoaArray : NSArray = gruppe
cocoaArray.writeToFile("pathToYourFile", atomically:true)
Upvotes: 0