wargi
wargi

Reputation: 11

What is the difference between Peer Macro and Member Macro in SwiftMacro?

Why does the Member Macro work in objc code, but the Peer Macro does not?🥲

//MARK: - Member Macro
@ObjCConvertMacro
class TestModel: NSObject, Codable {
    var convertCaseFromOptionalInt: Int?
    // Expand macro
    @objc
    var convertCaseFromOptionalIntObjc: NSNumber? {
        get {
            convertCaseFromOptionalInt as? NSNumber
        }
        set {
            convertCaseFromOptionalInt = newValue?.intValue
        }
    }
}

//MARK: - Peer Macro
class TestModel: NSObject, Codable {
    @ObjCConvertMacro
    var convertCaseFromOptionalInt: Int?
    // Expand macro
    @objc
    var convertCaseFromOptionalIntObjc: NSNumber? {
        get {
            convertCaseFromOptionalInt as? NSNumber
        }
        set {
            convertCaseFromOptionalInt = newValue?.intValue
        }
    }
}

I want to use Swift code in objc by bridging it with a peer macro..

Upvotes: 1

Views: 154

Answers (0)

Related Questions