Posts

Post not yet marked as solved
2 Replies
308 Views
import UIKit extension String { func toDate() -> Date? { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "MMMM d, yyyy h:mm a" dateFormatter.locale = Locale(identifier: "en_US_POSIX") dateFormatter.timeZone = .current return dateFormatter.date(from: self) } } let date = "October 3, 2008 7:00 PM".toDate()Hey guys, I'm getting inconsistent results from the above snippet. Inside of a Playground, it executes just fine and the date parses properly. In a project, the snippet fails and the date winds up nil. Any thoughts on why this could be?
Posted Last updated
.