Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Which Data Model type better?

I'm learning MVC design pattern.So I have a question which I'm so confusing about what is better. Code snippet :

  class DataModel: UIViewController {

struct Alerts {
static let DismissAlert = "Dismiss"
static let RecordingDisabledTitle = "Recording Disabled"
static let RecordingDisabledMessage = "You've disabled this app from recording your microphone. Check Settings."
static let RecordingFailedTitle = "Recording Failed"
static let RecordingFailedMessage = "Something went wrong with your recording."
static let AudioRecorderError = "Audio Recorder Error"
static let AudioSessionError = "Audio Session Error"
static let AudioRecordingError = "Audio Recording Error"
static let AudioFileError = "Audio File Error"
static let AudioEngineError = "Audio Engine Error"
}
let helpText: [String:String] = [
"startRecordText" : "Tap to record",
"recordingText" : "Recording...",
"pauseRecordText" : "Paused",
]

let hintText:[String] = [
    "Avoid noise to record better.",
    "Use pause button to pause recording progress",
    "Make some funny melody :D"
]

I don't know which is better and more efficiently:

Create a new struct in parent class to save data or Create properties such as array,dictionaries to storage data Hopefully you guys help me to explain this issues :D

Many thanks

I think you should use an enum to describe all the possible errors and alerts and you can associate a string raw value to them.

1 Answer

Agreed with Stefano, this snippet begs to be an enum. Swift enums are awesome, complicated, and extremely powerful, so you'll have a good time implementing it and it'll be useful for future projects.