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

用空的@protocal 实现容器类的伪泛型识别? #79

Closed
goodbless opened this issue Apr 16, 2016 · 5 comments
Closed

用空的@protocal 实现容器类的伪泛型识别? #79

goodbless opened this issue Apr 16, 2016 · 5 comments

Comments

@goodbless
Copy link

goodbless commented Apr 16, 2016

就是类似JSONModel的方案,

@protool  Dog;

@property (nonatomic, strong)NSArray<Dog>* dogs;

这样在YYClassPropertyInfo->_typeEncoding就拿到的是NSArray,这时候分离出Dog,就可以拿到容器类成员对象的类型了。可以作为modelContainerPropertyGenericClass的一个简便写法。

@ibireme
Copy link
Owner

ibireme commented Apr 16, 2016

稍后会再考虑下。

倒不是说不好,但总感觉这么写显得太 trick 了。。除了要多写一个 protocol 外,还要假定这个 protocol 和类名一样。另外这么写也会和 OC 新加的 Lightweight Generics 有点冲突。。

@goodbless
Copy link
Author

可惜Lightweight Generics是编译时特性,我也想过如果property能获取到Lightweight Generics的ObjectType就好了,可惜不行。

@molon
Copy link

molon commented May 18, 2016

其实这样似乎蛮好的,哈哈。
多谢这么trick的方法,即使作者不加,也会改源码放到项目里用。
否则不小心没全面的改一个属性名造成的隐患很蛋痛,而且也方便多了,Lightweight Generics特性不搞swift的我们也不需要关心哈。 😄

@molon
Copy link

molon commented May 25, 2016

@ibireme
今天比较无聊,就这个issue搞了个小玩意。
pseudo-generic
在这个issue的建议前提下,快速编码,已经commit,https://github.com/molon/MLAutoReplace
而且呢,Lightweight Generics只是看起来和protocol冲突,但是实际上两者可以并存的。

希望能增加你添加这个功能的兴趣,个人觉得这建议蛮好的,这样一来基本上就不需要写什么映射的玩意了。:)

@ibireme
Copy link
Owner

ibireme commented Jun 15, 2016

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