0

I'm making a third party license page for my app.

So i have a UITableView when each cell is the library name and when tapping it opens a new UIViewController with the licence text.

So what would be the best and efficient way to save and load an array of long strings?

static let MIT = ""

or

enum licence: String {
    MIT = ""
}

or

let licences = ["MIT": "", ]

or

loading from file

Or any other suggestion?

Thanks

ilan
  • 4,402
  • 6
  • 40
  • 76
  • If data is Static there is no change in that then you can use plist file also for saving the data – Bhupat Bheda Oct 18 '17 at 06:27
  • Yep, the strings don't change. It's just a list of third party licences. Would this be the nest practice? – ilan Oct 18 '17 at 06:28
  • So it would be better for go with Plist file just create one custom plist file and put the all data as the way of array or dictionary whatever you want and just load the file and get all data from file and save into array and show them in cell – Bhupat Bheda Oct 18 '17 at 06:30
  • I think enum of string would be fair, you array type would be an array of enum type. – Ahmad F Oct 18 '17 at 06:33

2 Answers2

3

I will consider it to be constant and what we frequently use in case of constant:

struct Constants {
    static let MIT = ""
}

Uses:

Constants.MIT

Source

Salman Ghumsani
  • 3,647
  • 2
  • 21
  • 34
0
  1. static variable is a variable that has been allocated "statically", meaning that its lifetime (or "extent") is the entire run of the program (take memory of app)
  2. enumerations in Swift are pure OOP and are much like a class (It may add a lot of methods such as rawValue which makes the element quite large, bad on performance and may have extra memory consumption etc...)
  3. local variables need to be initialized for example from file ;)

I suggest to create a model as you proposed: let licences = ["MIT": "plist file", ] Where plist/text file is read when specific VC is being shown (row tapped).

Tomasz Czyżak
  • 1,118
  • 12
  • 13