alibaba / alibaba/HandyJSON

swift 5.0\xcode10.2 Swift字典无法正确映射的模型

Open
#344 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
4.3k
Forks
677
PR merge metrics
No merged PRs in 30d

Description

这是我的字典:

```Swift
let value: [String: Float] = ["vectors": [1.0, 2.0]] as [String: Any]

struct VectorModel: HandyJSON {
var vectors: [CGFloat] = []
}
// 错误的取值
let model = VectorModel.deserialize(from: value)
// model.vectors 的值为 []

// 正确的取值
let model = VectorModel.deserialize(from: NSDictionary.init(dictionary: value))
```

不知道是不是和字典的类型有关?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the reported calls to VectorModel.deserialize(from:) and compare passing the Swift dictionary with passing NSDictionary.init(dictionary: value). Check whether the vectors field maps to [CGFloat] in both cases; done means the Swift dictionary produces the same expected [1.0, 2.0] value as the NSDictionary input.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.