Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何从Swift 3应用程序调用目标C方法?_Ios_Objective C_Swift_Mobile_Wit.ai - Fatal编程技术网

Ios 如何从Swift 3应用程序调用目标C方法?

Ios 如何从Swift 3应用程序调用目标C方法?,ios,objective-c,swift,mobile,wit.ai,Ios,Objective C,Swift,Mobile,Wit.ai,我正在尝试使用SDK,它是在Swift 3应用程序中用Objective C编写的 GitHub repo中的文档解释了如何使用特定的Objective C方法将文本字符串发送给Wit,但我不确定如何在我的应用程序中使用该方法,可能需要一些指导 解释字符串 将NSString发送到wit.ai进行解释。与发送语音输入相同,但带有文本 - (void) interpretString: (NSString *) string customData:(id)customData; 这就是我到目前为

我正在尝试使用SDK,它是在Swift 3应用程序中用Objective C编写的

GitHub repo中的文档解释了如何使用特定的Objective C方法将文本字符串发送给Wit,但我不确定如何在我的应用程序中使用该方法,可能需要一些指导

解释字符串

将NSString发送到wit.ai进行解释。与发送语音输入相同,但带有文本

- (void) interpretString: (NSString *) string customData:(id)customData;
这就是我到目前为止所做的:

import UIKit

class ViewController: UIViewController, WitDelegate {
    /**
     * Called when the Wit request is completed.
     * param outcomes a NSDictionary of outcomes returned by the Wit API. Outcomes are ordered by confidence, highest first. Each outcome contains (at least) the following keys:
     *       intent, entities[], confidence, _text. For more information please refer to our online documentation: https://wit.ai/docs/http/20141022#get-intent-via-text-link
     *
     * param messageId the message id returned by the api
     * param customData any data attached when starting the request. See [Wit sharedInstance toggleCaptureVoiceIntent:... (id)customData] and [[Wit sharedInstance] start:... (id)customData];
     * param error Nil if no error occurred during processing
     */
    public func witDidGraspIntent(_ outcomes: [Any]!, messageId: String!, customData: Any!, error e: Error!) {
        if ((e) != nil) {
            print("\(e.localizedDescription)")
            return
        }

        let outcomes : NSArray = outcomes! as NSArray
        let firstOutcome : NSDictionary = outcomes.object(at: 0) as! NSDictionary
        let intent : String = firstOutcome.object(forKey: "intent") as! String
        labelView!.text = intent
        labelView!.sizeToFit()
    }

    var labelView : UILabel?
    var witButton : WITMicButton?

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        // set the WitDelegate object
        Wit.sharedInstance().delegate = self

        // create the button
        let screen : CGRect = UIScreen.main.bounds
        let w : CGFloat = 100
        let rect : CGRect = CGRect(x: screen.size.width/2 - w/2, y: 60, width: w, height: 100)

        witButton = WITMicButton(frame: rect)
        self.view.addSubview(witButton!)

        // create the label
        labelView = UILabel(frame: CGRect(x: 0, y: 200, width: screen.size.width, height: 50))
        labelView!.textAlignment = .center
        labelView!.text = "intent"
        labelView!.textColor = UIColor.black
        labelView!.sizeToFit()
        self.view.addSubview(labelView!)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

这比你的另一个问题要好,但你不能说“没有错误”,也不能说实际的错误是什么!好吧,对不起,我要问不同的问题。你能不能使用编辑按钮或添加注释,然后告诉我们你收到的实际错误消息?问题是,我还没有正确的解决方案,错误代码对你没有多大帮助。我让应用程序运行了,但它的工作方式不正确。我已经编辑了你的问题,但你发布的问题完全令人困惑。这听起来像是一个移植问题,就像你试图移植整个API一样。你陈述和解释事情的顺序既尴尬又误导人,浪费了太多的时间,你对语言的掌握需要改进。在讨论技术细节时,清晰的沟通非常重要,因此值得花时间学习如何提出好的问题。请参阅顶部的“帮助”链接,询问一个好问题,并学习语言技能。这比你的其他问题要好,但你不能说“没有错误”。也不能说实际错误是什么!好吧,对不起,我要问不同的问题。你能不能使用编辑按钮或添加注释,然后告诉我们你收到的实际错误消息?问题是,我还没有正确的解决方案,错误代码对你没有多大帮助。我让应用程序运行了,但它的工作方式不正确。我已经编辑了你的问题,但你发布的问题完全令人困惑。这听起来像是一个移植问题,就像你试图移植整个API一样。你陈述和解释事情的顺序既尴尬又误导人,浪费了太多的时间,你对语言的掌握需要改进。在讨论技术细节时,清晰的沟通非常重要,因此值得花时间学习如何提出好的问题。请参阅顶部的“帮助”链接,了解如何提出一个好问题,并学习语言技能。