HandyJSON Cannot call value of non-function type 'Any.Type'

tcbh2hod  于 2022-11-13  发布在  其他
关注(0)|答案(5)|浏览(146)

No description provided.

7uzetpgm

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
}
}

deyfvvtc

deyfvvtc3#

@XDYB 按照你的方式改了还是不行
Incorrect argument label in call (have 'pointer:', expected 'type:')

self.init(pointer: unsafeBitCast(anyType, to: UnsafePointer.self))
报错
,两种方式都是这样

6bc51xsx

6bc51xsx4#

这是我之前提交的issue,#202 (comment)
经过 @XDYB 说的修改后,运行的非常流畅

ngynwnxp

ngynwnxp5#

@imwangxuesen@linmaojia 你下载 git clone https://github.com/alibaba/HandyJSON.git 一份到本地,然后查看 Metadata.swiftProperties.swift 文件里的内容,其实该库的那些代码已经更新到github上了,只是 没有提交到pod中心。

这里也要谢谢 @XDYB 的帮助👍

相关问题