Cannot assign a value of type error with xcode7

Asked 2 years ago, Updated 2 years ago, 81 views

delete side
varid:Int?

Various codes
appdelegate.id=self.data [indexPath.row]["id"]as Int

I'd like to save important data from the API to delete.
Cannot assign a value of type Int to a value of type Int?
It says

The other code I want to save the name is string, so
Cannot assign a value of type String to a value of type String?

It says

I don't know how to deal with this error since I set it to xcode7.
Thank you for your cooperation

ios swift xcode

2022-09-30 20:51

1 Answers

I don't know how to deal with this error since I set it to xcode7.

The part that has been changed since Xcode 6.3, and the Swift version is changed from 1.2.Read Apple's public documents directly.

Swift Blog Feb 18, 2015

The downcast format has changed since Swift 1.2.Downcasting to the Optional type goes from 」as から to 」as?

appdelegate.id=self.data [indexPath.row] ["id"] as Int

This is

appdelegate.id=self.data [indexPath.row]["id"]as? Int

If so, the error should no longer appear.


2022-09-30 20:51

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.