0

Goal: to master the ObjC <--> Swift API syntax
Problem: Working with multi-parameter function API.

I haven't been doing ObjC in years and now I need to interface ObjC with Swift packages.
Here's the Swift-Package code:

import Foundation

public struct RicStruct {
    public private(set) var text = "Hello, World!"

    public init() {}
    
    public func sayHello() -> String {
        "Hello Ric!"
    }
}

public class RicClass: NSObject {
    @objc public var msg = "Mother has a feeling, I might be too appealing."
    @objc public let text = "Hello Everybody!"
    
    override public init() {}
    
    @objc public func sayHello() {
        print(text)
    }
    
    @objc public func doSomething(msg: String) {
        print("Inside doSomething: \(msg)")
    }
    
    @objc public func doSomething(msg: String, answer: String) {
        print("Inside doSomething with msg: \(msg) and answer: \(answer)")
    }
    
    @objc public func sayHelloTo(whom: String) -> String {
        "Hello \(whom)!"
    }
}

I'm having trouble with the multi-parameter syntax.
Objective-C likes to append 'with' or 'to', etc. to parameter names. I've learned this via trial & error.

But I'm having trouble with the multi-parameter syntax:

enter image description here

Question: What's the correct syntax for multi-parameter Objective-C method calls?

Frederick C. Lee
  • 9,019
  • 17
  • 64
  • 105
  • 2
    Have you tried: [richClass doSomethingWithMsg: @"hello", andAnswer: @"world"]; or just: [richClass doSomethingWithMsg: @"hello", answer: @"world"]; – Mr Spring Jul 31 '21 at 21:59

1 Answers1

0

Simple Solution, adding the appropriate label:

enter image description here

Frederick C. Lee
  • 9,019
  • 17
  • 64
  • 105