I am doing some requests with an API that returns me the following sample :
[{
id = 1004;
"planning_id" = 7;
"started_on" = "2015-05-14";},
{
id = 1380;
"planning_id" = 8;
"started_on" = "2015-05-16";},
{
id = 1382;
"planning_id" = 8;
"started_on" = "2015-05-18"; }]
As you can see, the date value is returned as a string which is considered as AnyObject for now...
I am now trying to change it for all the dictionaries of the array so I can use the started_on value as a NSDate
Here is my code :
for i in 1..<myArray.count
{
let dateString = shiftsArray[i-1].objectForKey("started_on") as! String
//format date
var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
var dateFromString = dateFormatter.dateFromString(dateString)
shiftsArray[i-1].objectForKey("started_on") = dateFromString
}
However, I cannot run the code since I have an error for the last line : "Cannot assign a value of type 'NSDate?' to a value of type "AnyObject?".
The problem is that I don't know how to change the value type of the 'started_on' of the dictionnaries.
Thank you in advance,
I dont know how you set up things before this little snippet in you question but this is how I did:
Before:
After: