Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build- time error in xcode 9.2 "No 'decodeIfPresent' candidates produce the expected contextual result type 'AnyObject?" #105

Closed
ankushkushwaha opened this issue Feb 21, 2018 · 0 comments

Comments

@ankushkushwaha
Copy link
Contributor

I generated the Model classes from JSON. Apparently, tool has generic type as 'AnyObject'.
If some fields has null value in JSON, it will be exported as 'AnyObject' for Swift- struct -Codable format.

Problem: Xcode 9.2 does not allow to build the project with 'AnyObject' type properties in Codable structs. I am getting the following build time error:

No 'decodeIfPresent' candidates produce the expected contextual result type 'AnyObject?
screen shot 2018-02-21 at 2 53 33 pm

ankushkushwaha pushed a commit to ankushkushwaha/JSONExport that referenced this issue Feb 21, 2018
In Swift-Struct-Codable format 'decodeIfPresent' cannot
produce value of type 'Anyobject'. So changing geberic-type
from 'AnyObject'to 'String' for null json values will
allow to compile the xcode project

Fixes Ahmed-Ali#105
doegadoega pushed a commit to doegadoega/JSONExport that referenced this issue Jun 3, 2019
* origin/master: (75 commits)
  Fixed an issue with trying to figure the selected language from an UI element outside the UI thread
  nit: removing empty line
  Adding Outlaw JSON file to the project as the merge conflicts caused this to not to merge correctly
  Updating CHANGELOG.md
  Fixing the project file
  Updating CHANGELOG.md
  Updating CHANGELOG.md
  Updating CHANGELOG.md
  Updating CHANGELOG.md
  Updating CHANGELOG.md
  Updating CHANGELOG.md
  Updating GHANGELOG.md for release 1.0.9
  Update to Swift 4.2
  Fix: float type issue
  Java Gson for Android: Fix method name to be "optString" instead of "opt" to get String type value from JSONObject in constructor.
  Change generic type from 'AnyObject' to 'String' -> Fixes Ahmed-Ali#105
  added back credit file
  Added Swift-Codable-Struct with forced unwrapped option
  Migrate to Swift 4
  fix a complier error in SwiftyJSON - Class
  ...

# Conflicts:
#	.gitignore
#	JSONExport.xcodeproj/project.pbxproj
#	JSONExport/Supported Languages/Swift-Mappable.json
huabin pushed a commit that referenced this issue May 21, 2022
In Swift-Struct-Codable format 'decodeIfPresent' cannot
produce value of type 'Anyobject'. So changing geberic-type
from 'AnyObject'to 'String' for null json values will
allow to compile the xcode project

Fixes #105
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant