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

lmvvr0a8  于 2022-11-13  发布在  其他
关注(0)|答案(7)|浏览(291)

Xcode 9
Swift 4
Any help?

3hvapo4f

3hvapo4f1#

这是由于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
}
}

1szpjjfi

1szpjjfi2#

太感谢了,就是和type(of:)重名了,按照上面的修改,运行很顺畅

xytpbqjk

xytpbqjk3#

@XDYB 这上面的代码会被加入到下一个的Pod版本的库吗?

ctehm74n

ctehm74n4#

please use english language

mutmk8jj

mutmk8jj5#

@arashgood just following the instruction as @XDYB commented above, it did work.

qco9c6ql

qco9c6ql6#

@VictorZhang2014 it's not clear instruction!

5w9g7ksd

5w9g7ksd7#

@arashgood It did well for me. Another helping instruction is to download the whole project and run it in the simulator or iphone which always runs well.

@XDYB Sorry to copy your answer here.

This error is appeared by a type and type(of:)

Solution 1:

  1. Follow these instructions below and modification

-------------in the file 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
    }
}

-------------in the file of 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
    } 
}

-------------in the file of Metadata.swift-------------

guard let metaclass = Metadata.Class(anyType: superclass), metaclass.isSwiftClass else {
    return nil
}

Solution 2

  1. Follow these instructions below and modification
    -------------in the file of 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
    }
}

-------------in the file of 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
    }
}

相关问题