1

I'm trying to use wit-ai SDK, written in Objective C in a Swift 3 app.

The documentation in the GitHub repo explains how to use a particular Objective C method to send text string to Wit, but I'm not sure how to use that method in my app, and could use some guidance.

InterpretString

Sends an NSString to wit.ai for interpretation. Same as sending a voice input, but with text.

- (void) interpretString: (NSString *) string customData:(id)customData;

This is what I have so far:

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.
    }
}
clearlight
  • 12,255
  • 11
  • 57
  • 75
Taylan Kar
  • 21
  • 2
  • Its better than your other question, but you can't say this " without getting an error." and not state what the actual error is! – Gruntcakes Jan 01 '17 at 18:52
  • alright sorry I'm going to ask differently – Taylan Kar Jan 01 '17 at 18:55
  • Can't you use the edit button or add a comment and give us the actual error message you got? – uliwitness Jan 01 '17 at 21:57
  • Well the thing is that I don't have the right solution yet and the error code wouldn't help you much. I got the app running but it doesn't work the right way. – Taylan Kar Jan 01 '17 at 22:35
  • I already edited your question, but the question the way you posted it was absolutely confusing. It sounded like maybe a porting question, like you were trying to port the whole API. The order you presented and explained things was awkward and misleading, wasting too much time to get to the point, and your grasp of the language needs improvement. Since clear communication is so important when discussing technical details it's worth investing time learning how to ask good questions. See the help link at the top about asking a good question and also work on the language skills. – clearlight Jan 05 '17 at 17:28
  • Also, when editing your questions, click the help in the icon bar to see how to use the features such as quotation block, adding links, images. When referring to APIs, etc... be sure to use the proper name and syntax. I had to change it to wit-ai, for example, and why not make it a link to the GitHub repo so people can get a better idea of what you're doing, while not taking much space in your write-up? I did that for you too. – clearlight Jan 05 '17 at 17:31
  • I realize you're new here, your first post and there's a lot to learn, but this community includes a lot of seasoned professional engineers, so learning how to work with StackOverflow, ask clear questions, format questions, etc... will help you in school and as a professional. Consider spending some time in the review link at the top and learning the site and how to participate to strengthen your skills and grasp of the language, and technical terms, etc... – clearlight Jan 05 '17 at 17:33

0 Answers0