I am working on speech to text iOS 10 feature.
I want SFSpeechRecognitionTaskDelegate's delegate methods to be called for checking the completed results.
func speechRecognitionTask(_ task: SFSpeechRecognitionTask, didFinishRecognition recognitionResult: SFSpeechRecognitionResult);
But its any delegate method is not getting called.
Also I am curious about why its .delegate property which is not available for setting delegate to self.
Any Help will be appreciated. Thanks in advance.
Edited:
Also, The delegate Property set by the protocol is not found in the documentaion. i.e.
#property (nonatomic, weak) id<SFSpeechRecognitionTaskDelegate> delegate;
is not available in SFSpeechRecognitionTask.h file.
Is it necessary that we need property for that?
use:
self.speechRecognizer.recognitionTask(with: self.recognitionRequest!, delegate: self)
refer this article, It contains demo app on speechkit in swift,
https://www.appcoda.com/siri-speech-framework/
It works fine for me.
Related
I've subclassed UITextField and added two variables and a convenience function. One variables holds a String key and the other holds a reference to another TextField which is used to create a custom tab order.
All good except I've run into a small problem. Using the storyboard I'm not able to bind the IBOutlet in the controller to the text field elements that implement this subclass even though they are both the same type. I've had to set the IBOutlet variable to be a UITextField type, bind them and then set the IBOutlet back to the subclass.
This all works in Xcode5 using Objective-C so I assume this is an issue with the beta of XCode6 but just wanted confirm I wasn't missing something.
I am also playing with swift.. I can share what I checked when faced some problems, you can check these. Not sure though it is the solution for your problem.
1. Check class defined for subclass and main class
2. Check delegates defined for text fields.
3. Check if prototyping can solve your problem.
Beta 2 Release of XCode 6 has resolved this issue.
I just started OS X development with Cocoa, but I got many basic problems.
How can I detect text changed from NSTextField something like onTextChanged() in Java?
Someone said that make delegate, but I can't understand what is delegate, and what it does.
I use cocoa framework with Xcode 5.0.2.
Thanks, and sorry for my bad English :'(
In the class declaration add the NSTextFieldDelegate protocol:
#interface MyView : NSView <NSTextFieldDelegate>
Then in code set:
myTextField.delegate = self;
Now your textfield will send notifications to the delegate, and you can implement whichever delegate function you want (see NSText Delegate Method Implementations in the link below)
What you say you need now is to implement:
- (void)textDidChange:(NSNotification *)aNotification {
//Do stuff here
}
Reference: NSTextField Class
In-spite of writing code you can implement the same thing through binding as well. Just connect your textfield to the delegate of fileowners. Like that below:-
And then implement this below method. So that no need to define NSTextFieldDelegate protocol in header file and no need to set delegatein implementation file through code :-
-(void)controlTextDidChange:(NSNotification *)obj
{
}
When I use bindings I don't need to include the IBOutlet macro.
Ex.
#property NSString* stringToBind
Why is this?
When do we use the IBOutlet macro and when do we leave it out? I am confused because I thought we include the IBOutlet macro to when we want to use it as an object with interface builder.
What would happen if linked to an object (like would would normally do with an outlet) but excluded the IBOutlet macro? In other words created an outlet without the IBOutlet macro? It is optional in all cases? Is it just used to make things easier, so that they are detected?
Thanks in advance
As far as the compiler and linked are concerned, IBOutlet is a no-op. More specifically it is #define'd to nothing. Xcode and Interface Builder use static code analysis to figure out what to do, but it will have no impact on compiling or linking.
The NIB that is generated contains the names of the properties to connect when it is loaded and those names are resolved the same way that all other properties are resolved.
If you remove IBOutlet from a property declaration introduces a risk that the next time the NIB is generated, the link connection won't be made. I am not sure how Interface Builder handles that.
I have the following class:
#interface SpWindow : NSWindow <NSCoding> {
BOOL _editMode;
SpBgView *bgView;
} ...
... which I then call archive on. My encode method is as follows:
- (void) encodeWithCoder:(NSCoder *)aCoder {
NSLog(#"encodeWithCoder CALLED FOR SpWindow");
[super encodeWithCoder:aCoder];
NSLog(#"SpWindow's encodeWithCoder got past the super call");
[aCoder encodeObject:bgView forKey:#"bgView"];
[aCoder encodeBool:_editMode forKey:#"_editMode"];
}
... however the [super encodeWithCoder:aCoder]; bit results in the following in the console log:
encodeWithCoder CALLED FOR SpWindow
<SpWindow: 0x20009f660> does not support archiving
*** -[NSKeyedArchiver finalize]: warning: NSKeyedArchiver finalized without having had -finishEncoding called on it.
... according to the NSWindow documentation the class conforms to the NSCoding protocol, so I have no idea why I'm seeing this issue.
Any ideas ?
--- EDIT: The class reference for NSWindow shows:
Conforms to NSCoding (NSResponder)
... NOT just "Conforms to NSCoding" - so I guess does this mean that only the NSResponder bits conform to NSCoding ?
Straight from the NSWindow documentation:
Note: Although the NSWindow class inherits the NSCoding protocol from NSResponder, the class does not support coding. Legacy support for archivers exists but its use is deprecated and may not work. Any attempt to archive or unarchive an NSWindow object using a keyed coding object raises an NSInvalidArgumentException exception.
Does your class implement the entire protocol or just encodeWithCoder? Methods marked "required" are not optional.
OK, it looks like I'm a victim of my meddling with the MVC-model - NSview & NSWindow don't do the NSCoding thing.
I have an application where I have a main.m that returns NSApplicationMain(argc, (const char **) argv);.
I want to run code on -applicationDidFinishLaunching:, but I just dont see how to do it.
Can anyone help or have an example?
Thanks!
-Jason
The applicationDidFinishLaunching: method of the NSApplication delegate will be called when the app has finished loading. Many of the project templates setup a delegate. If you are using one just add the appropriate method to it.
If your project does not have an app delegate set up you will need to do that yourself. First, make a new class to act as your delegate (you can use an exiting one if there is something logically appropriate). Now make sure that class is instantiated in your MainMenu.nib. Finally, hook the delegate property of the "File's Owner" object to the instantiate delegate in IB.
Louis' answer is concise and spot-on. However, if the concept of delegate methods is new to you, you'd do well to check out the relevent documenation.