No description provided.
lyfkaqu11#
运行报错
7uzetpgm2#
这是由于type 和 type(of:) 重名!方式一:按照下面👇方式修改-------------Metadata.swift 中:-------------init?(anyType: Any.Type) {self.init(pointer: unsafeBitCast(anyType, to: UnsafePointer.self))if let kind = type(of: self).kind, kind != self.kind {return nil}}
-------------Properties.swift 中-------------func getProperties(forType type: Any.Type) -> [Property.Description]? {if let nominalType = Metadata.Struct(anyType: type) {return fetchProperties(nominalType: nominalType)} else if let nominalType = Metadata.Class(anyType: type) {return nominalType.properties()} else if let nominalType = Metadata.ObjcClassWrapper(anyType: type),let targetType = nominalType.targetType {return getProperties(forType: targetType)} else {return nil}}-------------Metadata.swift中-------------guard let metaclass = Metadata.Class(anyType: superclass), metaclass.isSwiftClass else {return nil}
方式二:按照下面👇方式修改-------------Metadata.swift 中:-------------init?(type anyType: Any.Type) {self.init(pointer: unsafeBitCast(anyType, to: UnsafePointer.self))if let kind = type(of: self).kind, kind != self.kind {return nil}}
-------------Properties.swift 中-------------func getProperties(forType anyType: Any.Type) -> [Property.Description]? {if let nominalType = Metadata.Struct(type: anyType) {return fetchProperties(nominalType: nominalType)} else if let nominalType = Metadata.Class(type: anyType) {return nominalType.properties()} else if let nominalType = Metadata.ObjcClassWrapper(type: anyType),let targetType = nominalType.targetType {return getProperties(forType: targetType)} else {return nil}}
deyfvvtc3#
@XDYB 按照你的方式改了还是不行Incorrect argument label in call (have 'pointer:', expected 'type:')在self.init(pointer: unsafeBitCast(anyType, to: UnsafePointer.self))报错,两种方式都是这样
6bc51xsx4#
这是我之前提交的issue,#202 (comment)经过 @XDYB 说的修改后,运行的非常流畅
ngynwnxp5#
@imwangxuesen@linmaojia 你下载 git clone https://github.com/alibaba/HandyJSON.git 一份到本地,然后查看 Metadata.swift 和 Properties.swift 文件里的内容,其实该库的那些代码已经更新到github上了,只是 没有提交到pod中心。
git clone https://github.com/alibaba/HandyJSON.git
Metadata.swift
Properties.swift
这里也要谢谢 @XDYB 的帮助👍
5条答案
按热度按时间lyfkaqu11#
运行报错
7uzetpgm2#
这是由于type 和 type(of:) 重名!
方式一:按照下面👇方式修改
-------------Metadata.swift 中:-------------
init?(anyType: Any.Type) {
self.init(pointer: unsafeBitCast(anyType, to: UnsafePointer.self))
if let kind = type(of: self).kind, kind != self.kind {
return nil
}
}
-------------Properties.swift 中-------------
func getProperties(forType type: Any.Type) -> [Property.Description]? {
if let nominalType = Metadata.Struct(anyType: type) {
return fetchProperties(nominalType: nominalType)
} else if let nominalType = Metadata.Class(anyType: type) {
return nominalType.properties()
} else if let nominalType = Metadata.ObjcClassWrapper(anyType: type),
let targetType = nominalType.targetType {
return getProperties(forType: targetType)
} else {
return nil
}
}
-------------Metadata.swift中-------------
guard let metaclass = Metadata.Class(anyType: superclass), metaclass.isSwiftClass else {
return nil
}
方式二:按照下面👇方式修改
-------------Metadata.swift 中:-------------
init?(type anyType: Any.Type) {
self.init(pointer: unsafeBitCast(anyType, to: UnsafePointer.self))
if let kind = type(of: self).kind, kind != self.kind {
return nil
}
}
-------------Properties.swift 中-------------
func getProperties(forType anyType: Any.Type) -> [Property.Description]? {
if let nominalType = Metadata.Struct(type: anyType) {
return fetchProperties(nominalType: nominalType)
} else if let nominalType = Metadata.Class(type: anyType) {
return nominalType.properties()
} else if let nominalType = Metadata.ObjcClassWrapper(type: anyType),
let targetType = nominalType.targetType {
return getProperties(forType: targetType)
} else {
return nil
}
}
deyfvvtc3#
@XDYB 按照你的方式改了还是不行
Incorrect argument label in call (have 'pointer:', expected 'type:')
在
self.init(pointer: unsafeBitCast(anyType, to: UnsafePointer.self))
报错
,两种方式都是这样
6bc51xsx4#
这是我之前提交的issue,#202 (comment)
经过 @XDYB 说的修改后,运行的非常流畅
ngynwnxp5#
@imwangxuesen@linmaojia 你下载
git clone https://github.com/alibaba/HandyJSON.git
一份到本地,然后查看Metadata.swift
和Properties.swift
文件里的内容,其实该库的那些代码已经更新到github上了,只是 没有提交到pod中心。这里也要谢谢 @XDYB 的帮助👍