Multiple Methods named '-setTransform:' found - iphone

-(void)rotateView:(id)sender {
CGAffineTransform rotateTransform = CGAffineTransformRotate(CGAffineTransformIdentity, M_PI);
[sender setTransform:rotateTransform];//the error is shown here
}
I am getting this caution error that shows up and says Multiple methods named -setTransform: found. It only shows up when I have #import AVFoundation/AVFoundation.h in my header file. Any suggestions? Thanks

Cast sender to the proper class type and the warning should go away:
[(YourClassHere *)sender setTransform:rotateTransform];
As sender is passed to rotateView: as type id Xcode cannot know what actual class type it is and by that which method to call.
Edit: Coincidentally just today Matt Gallagher of Cocoa With Love fame published an article about all kinds of issues caused by calling an ambiguous method on id in Objective-C.

Related

Sending 'MapAnnotation *__strong' to parameter of incompatible type 'id<MKAnnotation>'

I am getting a warning in the below mentioned line:
[self.mapView addAnnotation:addressAnnotation];
The warning is:
Sending 'MapAnnotation *__strong' to parameter of incompatible type 'id<MKAnnotation>'
Since I referred similar kind of posts I have to mention that, the header file of this class includes <MKAnnotation> and the forward declaration of MapAnnotation class is also available.
Please suggest.
To get rid of the warning, you have two choices:
Declare the class of self (whatever that class is), in its #interface statement, to conform to the protocol.
Suppress the warning by changing this:
[self.mapView addAnnotation:addressAnnotation];
to this:
[self.mapView addAnnotation:(id)addressAnnotation];
The solution in my case was to add "s" for addAnnotation.
[self.mapView addAnnotations:addressAnnotation];

How to resolve warning "No '-modelLayer' method found" for CALayer class in iPhone unit test

I'm getting the warning that no '-modelLayer' method is found for the class CALayer in the following code. According to the CALayer class reference the modelLayer method does exist. This code executes correctly, so this confirms that the implementation is there at runtime. I presume I just need to add some casting to get rid of the warning, but I'm not sure what to cast to.
How can I resolve the warning?
I'm using Xcode 4.0 Build 4A278b.
Code:
CALayer * layer = (CALayer *)(coinView.layer);
CGRect newCoinFrame = [[layer modelLayer] frame]; //warning on this line
Warning:
CoinsToSlotViewControllerTest.m:138: warning: no '-modelLayer' method found
CALayer ref:
http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html
I think you need to #import <QuartzCore/QuartzCore.h>.

How to obtain scanned barcode type with zxing library?

How i can obtain bar code type with zxing library? Delegate method return only barcode in text.
The delegate call back is,
- (void)decoder:(Decoder *)decoder didDecodeImage:(UIImage *)image usingSubset:(UIImage *)subset withResult:(TwoDDecoderResult *)twoDResult {
The readers property in Decoder.mm is a list of FormatReaders.
#interface FormatReader : NSObject {
zxing::Reader *reader_;
}
The reader_ variable in FormatReader will be a C++ subclass of zxing::Reader, like QRCodeReader. Checking this class name will help identify what symbology you're getting. Beware some of them are 'MultiFormat' readers that combine other readers, so you might have to do some clever inspection.
See How to get class name? for how to get class name in C++.
If you end up making helpful modifications, make sure to submit a patch back to zxing. Good luck!

Changing Backlight Level, iPhone

I searched around for a way to set the backlight level within an app on the iPhone. I found a solution here:
http://www.iphonedevsdk.com/forum/29097-post3.html
The problem I have is, when I add this to my app I get an error and a warning. My code is as follows:
#include "GraphicsServices.h"
- (void) viewWillAppear:(BOOL)animated
{
NSNumber *bl = (NSNumber*) CFPreferencesCopyAppValue(CFSTR("SBBacklightLevel" ), CFSTR("com.apple.springboard"));
previousBacklightLevel = [bl floatValue];
//Error here : incompatible types in assignment
[bl release];
GSEventSetBacklightLevel(0.5f);
// Warning here : implicit declaration of function 'GSEventSetBacklightLevel'
}
//...The rest of my app
- (void)applicationWillTerminate:(UIApplication *)TheNameOfMyAppIsHere
{
GSEventSetBacklightLevel(previousBacklightLevel);
}
I am unsure of what is causing this. I also don't really know what needs to be in my .h file here, but I have:
NSNumber *previousBacklightLevel;
EDIT// Changed
NSNumber *previousBacklightLevel
to
float previousBacklightLevel;
as suggested and this sorted the incompatible types in assignment error.
Now left with:
"_GSEventSetBacklightLevel", referenced from:
-[MyAppViewController viewWillAppear:] in MyAppViewController.o
-[MyAppViewController applicationWillTerminate] in MyAppViewController.o
symbol(s) not found
collect2: ld returned 1 exit status
Not sure how to fix this one either!
Any help would be appreciated,
// EDIT
All problems sorted. Thanks to all who helped me out. I really do appreciate it and can't wait till I can give a little back, by answering some questions.
Many thanks,
Stu
The reason you are getting a warning is because GSEventSetBacklightLevel() is a private API not declared in any of of the SDK headers. If you are planning to submit this to the app store your app will get rejected if you call it. If this is for a jailbroken device, you can just declare the function yourself.
void GSEventSetBacklightLevel(float level);
The reason you are getting the error is because you are trying to assign a float (which is a scalar) to an NSNumber *. You probably want to change previousBacklightLevel to be a float.
you can add the private framework by jus drag and drop to your xcode project from /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/System/Library/PrivateFrameworks/GraphicsServices.framework and also import the #import "GraphicsServices.h" header in your .h file

How to use self class method on iPhone? (conceptual question)

I write an instance method in ClassName.m:
-(void)methodName:(paraType)parameter
{...}
And call it using [self methodName:parameter]; A warning will pop up, but the code still runs successfully.
Is this because I haven't created an instance of the class? Why the method still runs normally? And what is the correct way to call self method to prevent the warning?
Well the first step in receiving help with a warning would be to post the warning :)
I am assuming it is something about an unrecognized message? If so it's because although the compiler sees the call to "methodName" it does not know if that is valid for the object or not.
I would guess your code looks like;
-(void) someFunc
{
...
[self methodName:parameter];
...
}
-(void)methodName:(paraType)parameter
{
...
}
You can either;
a) Place the 'methodName' function earlier in the file so the compiler has seen it before it's used in calls.
b) declare it in the class interface. E.g.
// Foo.h
#interface Foo {
...
}
-(void) methodName:(paraType)parameter;
#end
What is the warning that you get?
Do you have a definition of the method in your header file?
The syntax you use is the propper way of calling method on self.
The method will work because Objective-C methods are resolved at run-time. I expect the warning you get is something like "Object Foo may not respond to -methodName:" and then it tells you that it's defaulting the return type to id. That's because the compiler hasn't seen a declaration or definition of -methodName: by the time it compiles the code where you call it. To remove the warning, declare the method in either the class's interface or a category on the class.
If you are getting a warning it might be because the method signature isn't in an interface.
#interface foo ....
-(void)method;
Once the implementation is written the warning should go away since it's not the first time the compiler has seen the method. It will work without doing this, but the warning message is annoying.