0

I am currently trying to save an Array of Dictionaries to NSUserDefaults. I originally planned to have the type be Array<Dictionary<String,String>> but that does not appear to be the case here. To start, I am getting the String values from the following UI objects:

@IBOutlet weak var name: UITextField!

@IBOutlet weak var instructor: UITextField!

@IBOutlet weak var time: UIDatePicker! 

And then saving it into a Dictionary like so:

let values = ["name" : self.name.text, "instructor" : self.instructor.text, "date" : self.time.date.description]

However the Dictionary's type is inferred as Array<Dictionary<String,String!>> not Array<Dictionary<String,String>>. The problem seems to be that self.name.text and self.instructor.text returns String!, but self.time.date.description returns String.

I think it would be possible to ignore these and continue on, but I want to understand what is going on here rather than continue and hope it doesn't break something in the future.

PopKernel
  • 4,110
  • 5
  • 29
  • 51
  • 1
    This may help: [What does an exclamation mark mean in the Swift language?][1] [1]: http://stackoverflow.com/questions/24018327/what-does-an-exclamation-mark-mean-in-the-swift-language – atwalsh Jan 24 '15 at 21:06

1 Answers1

0

According to iOS Developer Library, a UITextField text property, returns a !String (Source). The description in self.time.date.description represents a date object as String (Source) and is common used for debugging (a better practice to represent a NSDate object as a String is to use a DateFormatter)

Ramiz Wachtler
  • 5,623
  • 2
  • 28
  • 33