NSValue may not respond to... warning - iphone

I'm getting a warning in XCode which says NSValue may not respond to +valueWithCMTime:' but I'm not sure what I'm doing wrong. In my header file, I have this:
#import <Foundation/Foundation.h>
#import <CoreMedia/CoreMedia.h>
...
-(void)displayTime:(CMTime)time;
and in my implementation file, I have this:
-(void)displayTime:(CMTime)time
{
//This line has the warning
[mutableArray addObject:[NSValue valueWithCMTime:time]];
}
I've used the above line elsewhere in another class and there's no warning, so what could be missing from this one? Is it something to do with the way the method is set up?

You've probably forgotten to import the AVFoundation headers.
#import <AVFoundation/AVFoundation.h>

The iPhone class NSValue has no valueWithCMTime.
Check out the online documentation
It is added by AVFoundation framework, as documented here.
Added the corresponding header inclusion :
#import <AVFoundation/AVFoundation.h>

Make an NSMutableArray.... because you need an NSValue

Related

Expected identifier or '(' error before #class

I have these 2 classes:
ViewController.h
#import <UIKit/UIKit.h>
#import "UICustomButton.h"
#interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate>{
...
ViewController.m
#import "ViewController.h"
#implementation ViewController
...
UICustomButton.h
#import <UIKit/UIKit.h>
#class ViewController;
#interface UICustomButton : UIButton{
...
UICustomButton.m
#import "UICustomButton.h"
#import "ViewController.h"
#implementation UICustomButton
...
And I get the following errors
1 Expected identifier or '(' - in file UICustomButton.h just before #class
2 Expected ')' - also there
3 Expected a type - when I try to use ViewController in UICustomButton.h
4 in UiCustomButton.m I also get the error
After two hours of googling and trying, I just can't see the problem. Can you please help?
SOLUTION:
Rewriting everything was a good ideea. It made me see that in the file ViewController.m I had accidentally typed a paranthesis '(' on top at the beginning of the file. The compiler didn't poit it out, only UICustomButton.H generated errors.
Don't be afraid to restart/scrap and recreate a class. As you gain more experience correcting complex errors becomes a lot easier.
I'm completely serious about you needing to restart creating this class. Since apparently you can't interpret the message that the compiler is telling you it will take much longer for you to figure out the issue than creating another class, copying the business logic there and deleting the current implementation. Your choice, spend 10 minutes recreating the file or spend another who knows many hours trying to get the syntax Ok.
Even the professionals feel it a strong tool to restart when it's needed. Marshall Huss from Treehouse explains in this podcast why it was preferrable for him too.
PS: and best, you can rename the new class to the old name once you're done.
Looks like you are misspelling ViewController.h. You have Viewcontroller.h in your #import line

Cannot use imported classes methods with cocos2d

There is a problem, I just installed cocos2d for iPhone.
The first problem was that it wasn't recognizing any header like CCDirectory.h for example.
So I turned on user search paths in the project, but this way I could just import the header and have an object pointer without getting any warning, but methods aren't recognized.
It's hard to explain, so see this code:
Header:
#import <UIKit/UIKit.h>
#import <CCMenuItem.h>
#import <cocos2d.h>
Inside applicationDidFinishLaunching:
CCMenuItem* item; // This does not give a warning, except for the "unused variable"
// But the class is recognized
[CCMenuItem setFontName: #""]; // Warning
The warning is:
Class method '+setFontName:' not found (return type default to 'id')
And it doesn't recognize any other method, just NSObject's methods.
Are you sure the methods you are calling exists in that class? CCMenuItem doesn't contain a static method named setFontName. Try changing CCMenuItem to CCMenuItemFont.
[CCMenuItemFont setFontName: #""];

receiver type *** for instance message is a forward declaration

In my iOS5 app, I have NSObject States class, and trying to init it:
states = [states init];
here is init method in States:
- (id) init
{
if ((self = [super init]))
{
pickedGlasses = 0;
}
return self;
}
But there is error in the line states = [states init];
receiver type "States" for instance message is a forward declaration
What does it mean? What am I doing wrong?
That basically means that you need to import the .h file containing the declaration of States.
However, there is a lot of other stuff wrong with your code.
You're -init'ing an object without +alloc'ing it. That won't work
You're declaring an object as a non-pointer type, that won't work either
You're not calling [super init] in -init.
You've declared the class using #class in the header, but never imported the class.
FWIW, I got this error when I was implementing core data in to an existing project. It turned out I forgot to link CoreData.h to my project. I had already added the CoreData framework to my project but solved the issue by linking to the framework in my pre-compiled header just like Apple's templates do:
#import <Availability.h>
#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#endif
I got this sort of message when I had two files that depended on each other. The tricky thing here is that you'll get a circular reference if you just try to import each other (class A imports class B, class B imports class A) from their header files. So what you would do is instead place a forward (#class A) declaration in one of the classes' (class B's) header file. However, when attempting to use an ivar of class A within the implementation of class B, this very error comes up, merely adding an #import "A.h" in the .m file of class B fixed the problem for me.
I was trying to use #class "Myclass.h".
When I changed it to #import "Myclass.h", it worked fine.
If you are getting this error while trying to use Swift class or method in Objective C: you forgot one of 2 steps Apple defined on this diagram:
Example:
Error shows up in your Test.m file:
Receiver 'MyClass' for class message is a forward declaration
In Obj-C files:
Step 1: check that Test.h has
#class MyClass;
Step 2: find *-Swift.h file name in Build Settings (look for Objective-C Generated Interface Header Name). Name will be something like MyModule-Swift.h
Step 3: check that Test.m imports the above header
#import <MyModule/MyModule-Swift.h>
In Swift file:
Ensure MyClass (or it's base class) inherits NSObject class.
Ensure #objc is before each method you want call from Obj-C.
Also, check Target Membership section (in File Inspector).
You are using
States states;
where as you should use
States *states;
Your init method should be like this
-(id)init {
if( (self = [super init]) ) {
pickedGlasses = 0;
}
return self;
}
Now finally when you are going to create an object for States class you should do it like this.
State *states = [[States alloc] init];
I am not saying this is the best way of doing this. But it may help you understand the very basic use of initializing objects.
Check if you imported the header files of classes that are throwing this error.
Make sure the prototype for your unit method is in the .h file.
Because you're calling the method higher in the file than you're defining it, you get this message. Alternatively, you could rearrange your methods, so that callers are lower in the file than the methods they call.
There are two related error messages that may tell you something is wrong with declarations and/or imports.
The first is the one you are referring to, which can be generated by NOT putting an #import in your .m (or .pch file) while declaring an #class in your .h.
The second you might see, if you had a method in your States class like:
- (void)logout:(NSTimer *)timer
after adding the #import is this:
No visible #interface for "States" declares the selector 'logout:'
If you see this, you need to check and see if you declared your "logout" method (in this instance) in the .h file of the class you're importing or forwarding.
So in your case, you would need a:
- (void)logout:(NSTimer *)timer;
in your States class's .h to make one or both of these related errors disappear.

Cannot find protocol declaration for 'NSPasteboardWriting'

I am getting this error
Cannot find protocol declaration for 'NSPasteboardWriting'
i have created the class
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#interface ErrorLog : NSObject<NSCoding, NSPasteboardWriting, NSPasteboardReading> {
}
#end
Can any one tell me that whether i am missing some header file or whats the reason for that?
NSPasteboardWriting is Available in Mac OS X v10.6 and later.
check your project setting(Base SDK).
Import the header file in which NSPasteboardWriting and NSPasteboardReading protocols are declared. Also make sure you have the protocols in the class specified.

Expected Specifier qualifier list error

Hey guys, I know this problem caused due to the absent of importing header
But in my case, I've included the header but I still got the error?! What happens?
#import <Foundation/Foundation.h>
#import "WikitudeARCustomMenuButtonDelegate.h"
#import "DetailedARViewController.h"
#interface CustomMenuButtonDelegateImpl1 : NSObject <WikitudeARCustomMenuButtonDelegate>
{
DetailedARViewController *ARViewController;
}
#end
Make sure that "DetailedARViewController.h" really does define DetailedARViewController; in particular, check for subtle errors like misspellings or a declaration accidentally commented out.