alibaba / alibaba/HandyJSON

关于被@objc标记的enum 报错的问题 -[__SwiftValue longLongValue]: unrecognized selector sent to instance 0x600001af8180

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

Description

@objc enum TestType: Int, HandyJSONEnum {
case none = 0
case type = 1
case type2 = 2
}

class TestData: HandyJSON {
@objc var data: Int = 0

@objc var type: TestType = .none
}

![截屏2021-05-25 下午3 54 27](https://user-images.githubusercontent.com/10608010/119461072-ed974500-bd71-11eb-9339-5cf2e800c023.png)

需求是:
我们OC、Swift混合开发,OC中需要使用Swift中的枚举,因此枚举被标记为@objc,但是这时解析json数据时就会报上面的错误。

我目前的解决方法是修改HandyJSON源码:

![截屏2021-05-25 下午4 00 47](https://user-images.githubusercontent.com/10608010/119461568-69918d00-bd72-11eb-86eb-f317de954a15.png)

请问这个目前有什么好的解决方案吗?还是我没找到正确的方案?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the @objc enum TestType and the TestData.type property in the provided reproduction, then trace HandyJSON's JSON parsing path for enum properties. Reproduce the __SwiftValue longLongValue error with the shown model and JSON input; done means @objc-marked Int-backed enums deserialize without that exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
backend
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.