I've got a call like this [Class method] and a warning saying that Class may not
respond to "method" message.
The "method" message does not indeed exist but my code use unknown message catching
(using forwardingTargetForSelector) so it will run fine and it is build to run that way.
How can I hide this annoying warning ?
If you intend to send a possibly-unimplemented message to an object, and you know that you're going to catch failures, you should use the invocation:
id myClone = [anObject performSelector:#selector(copy)];
That declares your intent more directly that you are calling a method that may not exist, and you're cool with that. This is a more clear way to do it than to suppress the warning or fake out the method.
You could define a category that declares that method. Having the definition in scope at the time of compilation would avoid the warning. Something like
#interface MyClass (ShutUpTheCompilerMethods)
- (void)method;
#end
...
[MyClass method] //no warning here
Related
I am trying to update my Xamarin Mixpanel iOS bindings that I have here. While updating I figured I'd try re-enable a thing I had disabled before I continue to roll out updates all the way to the latest 5.0 release.
Current status is I am attempting to bind v3.6.2 (which is a little outdated) and I am having issues with the binding of some protocol/interface things. The source file that is being bound is MixpanelType.h.
A short example of this is
#protocol MixpanelType <NSObject>
- (BOOL)equalToMixpanelType:(id<MixpanelType>)rhs;
#end
#interface NSString (MixpanelTypeCategory) <MixpanelType>
#end
The generated code that comes out of objective sharpie looks like this,
// #protocol MixpanelType <NSObject>
/*
Check whether adding [Model] to this declaration is appropriate.
[Model] is used to generate a C# class that implements this protocol,
and might be useful for protocols that consumers are supposed to implement,
since consumers can subclass the generated class instead of implementing
the generated interface. If consumers are not supposed to implement this
protocol, then [Model] is redundant and will generate code that will never
be used.
*/[Protocol]
[BaseType (typeof(NSObject))]
interface MixpanelType
{
// #required -(BOOL)equalToMixpanelType:(id<MixpanelType>)rhs;
[Abstract]
[Export ("equalToMixpanelType:")]
bool EqualToMixpanelType (MixpanelType rhs);
}
// #interface MixpanelTypeCategory (NSString) <MixpanelType>
[Category]
[BaseType (typeof(NSString))]
interface NSString_MixpanelTypeCategory : IMixpanelType
{
}
I don't understand Category, Model, or Protocols in objective-c is so I am not entirely sure what it is trying to become. Based on the other things in MixpanelType.h it looks like the code is just trying to allow certain class types to exist.
The code is natively used in a method like this,
- (void)addGroup:(NSString *)groupKey groupID:(id<MixpanelType>)groupID {
which gets bound automatically to look like:
// -(void)addGroup:(NSString * _Nonnull)groupKey groupID:(id<MixpanelType> _Nonnull)groupID;
[Export ("addGroup:groupID:")]
void AddGroup (string groupKey, MixpanelType groupID);
I am unsure if MixpanelType is meant to be IMixpanelType and I am unsure if things like NSString_MixpanelTypeCategory are meant to exist.
Keeping it as above (but changing MixpanelType to `IMixpanelType) and attempting to compile I get the following errors:
Xam.Plugin.Mixpanel.iOS/NSString_MixpanelTypeCategory.g.cs(51,69,51,83): error CS0714: 'NSString_MixpanelTypeCategory': static classes cannot implement interfaces
Xam.Plugin.Mixpanel.iOS/NSString_MixpanelTypeCategory.g.cs(51,69,51,83): error CS0535: 'NSString_MixpanelTypeCategory' does not implement interface member 'IIMixpanelType.EqualToMixpanelType(IMixpanelType)'
Xam.Plugin.Mixpanel.iOS/NSString_MixpanelTypeCategory.g.cs(51,69,51,83): error CS0535: 'NSString_MixpanelTypeCategory' does not implement interface member 'INativeObject.Handle'
Xam.Plugin.Mixpanel.iOS/NSString_MixpanelTypeCategory.g.cs(51,69,51,83): error CS0535: 'NSString_MixpanelTypeCategory' does not implement interface member 'IDisposable.Dispose()'
The first error is odd as this isn't a static class.
The second error is odd and I can't get rid of it by implementing the method.
The third and fourth errors are odd because this class has a base type of NSString and I thought this would have been handled.
Any help on this so I can successfully bind the entire library without MixpanelGroups being disabled would be appreciated.
I would like to learn what this error message is.
imports.ui.dateMenu.DateMenuButton.prototype.hide()
When I run above in lookingGlass, I get below error
<exception Error: Can't convert to pointer on .Gjs_ui_dateMenu_DateMenuButton.prototype; only on instances>
Can any one explain in detail.
Thanks.
JavaScript has prototypal inheritance — meaning that DateMenuButton.prototype is an object that contains DateMenuButton's methods, but it is not a DateMenuButton itself. So when you call DateMenuButton.prototype.hide(), you are calling DateMenuButton's hide() method on an object that is not a DateMenuButton. This will give you an error. The error message is not particularly clear but "can't ___ on prototype, only on instances" is a hint about what's going on.
To call this method, you will need an actual DateMenuButton object.
Here is some further reading material on prototypal inheritance: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain
I know that it is nonsense (or there is no chance) for variables that its value is unknowable until the runtime.
Let's assume that you have a method like this:
public void Foo (BarEnum barVal)
{
//...
if(barVal == BarEnum.UnappropriateForFooMethod)
throw new BlaBlaException("Invalid barVal for Foo method ->" + barVal);
//...
}
This method will already throw an exception for unappropriate parameter. But I intend to warn developer that before run code and get an exception. Main idea is that. It is not important that if she/he do not care about warnings or turned off the warning messages, her/him code will get an exception anyway.
I guess that it is possible with built-in attributes. Like Obsolete. But I could not find anything...
If there is no attribute for this purpose, I am open to suggestions for custom solutions.
From .NET Framework 4 and later there's something called Code Contracts (on GitHub). Never tried it, but looks like what you seek.
There's also Roslyn. Also haven't work with it, but probably does at least something that you want. Being a super-tool, it is probably a bit unwieldy and verbose for your needs.
One workaround to this problem, without using external tools, is to thoroughly review the code.
I'm a bit confused why my NSThread cannot be instantiated using a selector due to a runtime error
target does not implement selector (*** -[FileSearcher processFilesAsync:])
The function is defined like this
func processFilesAsync(#data: [String])
and the NSThread will be created this way:
NSThread(target: self, selector: "processFilesAsync:", object: itemsPerThread[i])
"itemsPerThread" is just a dictionary with a String-Array as values.
As far as I know this should work as the method I want to invoke defines an argument and the selector I pass into NSThread's init() method indicates that the target method expects exactly one argument.
I already tried using Swift's "Selector" type instead of only a string but this didn't work as well. I also tried to change the method's type from "[String]" to "AnyObject" which didn't work, too.
Does anybody have a clue what might be wrong?
All of the code above lies within the same class.
I'm using Xcode 6 Beta 5.
Edit
I figured out that is has to do something with the parameter. I implemented a dummy method without parameters and tried to set this as target and it worked. As soon as I modified it to use a parameter as well -> same as above.
Found it. All I had to do was to change the parameter's type from AnyObject to AnyObject?. It even works with specialised types (in my case [String]? instead of [String]).
Of course, because you can call it nil as parameter...
I have a category (on NSDate) that contains a method that is only called from another method within the category, so there is no need to expose the method in the category's header file.
However, as expected, if I call the method from a unit test, the compiler shouts that
No visible #interface for 'NSDate' declares the selector 'myMethod:'
I'd like to be able to turn off these particular errors (for the unit test target only, of course).
Can someone point me in the direction of the correct compiler flag?
Instead of turning them off why not just redeclare it? If you turn the warnings off completely then you lose the fact that the compiler will give you warnings in genuine places.
So just declare it above the unit test
#interface NSDate (UnitTests)
// your method sig
#end
#implementation YourUnitTest
//...