0

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])
}
}
Yvana
  • 13
  • 7

2 Answers2

1

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"]
    }
}
Grimxn
  • 22,115
  • 10
  • 72
  • 85
0

You can bridge a Swift array to a NSArray.

doing something like:

let cocoaArray : NSArray = gruppe
cocoaArray.writeToFile("pathToYourFile", atomically:true)
Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215