I saw other questions related to this error, but I did not see anyone mentioning what I am experiencing right now. Please note that before converting to Swift 4, I had no problems with this code.
The following is the violation code:
let verseNotification = NSManagedObject(entity: entity, insertInto: self.managedObjectContext) as! VerseNotification
verseNotification.date_scheduled = NSDate(timeIntervalSinceNow: finalTimeToScheduleSinceNow)
Note that the attribute date_scheduledis of type Date:
@NSManaged public var date_scheduled: Date?
When I create a deployment application in DEBUG on my physical iPhone (iPhone 7), I get the following error (after converting from Swift 3 to Swift 4):
Cannot assign value of type 'NSDate' to type 'Date?' - Insert 'as Date'
Execution, as they say, fixes the problem ... So now my code is this:
verseNotification.date_scheduled = NSDate(timeIntervalSinceNow: finalTimeToScheduleSinceNow) as Date
... until I switch the target to the simulator. When I switch the target to the Simulator iPhone 7 device, now I get the following error:
'NSDate' is not implicitly convertible to 'Date'; did you mean to use 'as' to explicitly convert?
, , AM Date. , Simulator iPhone 7 - as Date, .
? ?
, "Generic Device", , .
UPDATE
- .
iPhone 7, Core Data date_scheduled Date.
, Simulator iPhone 7, Core Date date_scheduled NSDate.
Swift 4 Xcode 9? , Swift 3 Swift 4?