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

[SR-6731] PropertyListDecoder unable to decode __NSCFType #3748

Open
krzyzanowskim opened this issue Jan 9, 2018 · 3 comments
Open

[SR-6731] PropertyListDecoder unable to decode __NSCFType #3748

krzyzanowskim opened this issue Jan 9, 2018 · 3 comments

Comments

@krzyzanowskim
Copy link
Contributor

Previous ID SR-6731
Radar None
Original Reporter @krzyzanowskim
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 243c24973c4c93e917da850b1907c06d

Issue Description:

The plist file can store NSObject aka AnyObject aka Any aka CFTypeRef aka NSCFType and SwiftFoundation NSKeyedArchiver can read those.

The PropertyListSerialization is able to handle that too. YET, there is no way to decode this value using Decodable and PropertyListDecoder.

error is: eg. "Expected to decode Data but found __NSCFType instead."

I wonder if is it possible to (any)

  1. bitcast those to Any

  2. treat as raw bytes (return Data)

anything is better than throw error.

@belkadan
Copy link

cc @phausler

@phausler
Copy link
Member

PropertyListSerialization cannot handle Any. __NSCFTypes should always be non bridged CF object refs.

Only the following types are permissible to PropertyListSerialization (note this is different than PropertyListDecoder btw).

https://developer.apple.com/library/content/documentation/General/Conceptual/DevPedia-CocoaCore/PropertyList.html

Array, Dictionary, String, Data, Date, Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Int, UInt, Float, Double, Bool, NSArray, NSDictionary, NSString, NSData, NSDate, NSNumber, CFArray, CFDictionary, CFString, CFData, CFDate, CFNumber, and CFBoolean should be the only types that can exist in a property list. (it is worth noting that any of the collection types, ala Array or NSArray MUST ONLY contain property list types and Dictionaries and NSDictionaries MUST ONLY contain String/NSString/CFString keys and MUST ONLY contain property list values)

Now that all being said: it is quite possible via the Codable protocol to marshal any structured type into a decomposition that is represented by those types.

@phausler
Copy link
Member

Perhaps it might be useful for a code-example of how you are getting this error.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants