Problem in Importing File - iphone

I am importing File "FieldActivityViewController.h".But Showing an error
"/Users/rupeshnandha/Downloads/AQMD
Release 3/Classes/InputChoice.h:22:0
Expected specifier-qualifier-list
before 'FieldActivityViewController'
in /Users/rupeshnandha/Downloads/AQMD
Release 3/Classes/InputChoice.h"
As is a code Written in "InputChoice.h"
#import "FieldActivityViewController.h"
#protocol InputChoiceProtocol <NSObject>
#required
-(void) inputChoiceSelectedIndex :(int) index;
#end
#interface InputChoice : UIViewController {
//NSString *keyString;
FieldActivityViewController *field_act;
NSMutableArray *selectionArray;
IBOutlet UITableView *table;
NSObject<InputChoiceProtocol> *delegate;
// IBOutlet UIPickerView *picker;
}
#property (nonatomic,retain) NSArray *selectionArray;
#property (nonatomic,retain) FieldActivityViewController *field_act;
#property (nonatomic,retain) NSObject<InputChoiceProtocol> *delegate;
#end

It's not the good practice to import the application classes in .h files.
Try with forward class declaration and import you FieldActivityViewController file in .h
Use with forward class declaration #class FieldActivityViewController; at the place of your import statement.

use #class FieldActivityViewController

Most likely cause is that you have a circular dependency. InputChoice.h imports FieldActivityViewController.h and FieldActivityViewController.h imports InputChoice.h (not necessarily directly).
The best solution is to move the imports out of the header file into the .m file and put
#class FieldActivityViewController;
in InputChoice.h and
#class InputChoice
in FieldActivityViewController.h (or whichever header has InputChoic.h in it.

Related

Subclassing a subclass of UIImageView - Forward declaration errors

I have read question after question about people getting the same error as me, but I simply do not understand them, so before you go searching for duplicate questions, maybe someone can explain to me what I am doing wrong with this subclassing deal.
I have a subclass of UIImageView called swapView that I want to subclass to override the method -(void)count for special cases. I went to subclass this as I have any pre-existing UIKit class, but when I tried to build and run the project, I get this error:
Attempting to use the forward class 'swapView' as superclass of 'coinView'
I have tried putting both the #import statement of swapView and #class swapView in coinView.h and I've tried putting the import statement in coinView.m, but it refuses to build because of this continued error. If I move the import statement into the .m file, all references to the superclass's methods and properties, such as #property (nonatomic) int max; cause errors as well.
What am I doing wrong?
swapView.h
#import <UIKit/UIKit.h>
#import "ViewController.h"
#class ViewController;
#interface swapView : UIImageView
{
NSTimer* tmr;
}
#property (nonatomic) int current;
#property (nonatomic) int max;
#property (nonatomic, retain) UIImage* firstImage;
#property (nonatomic, retain) UIImage* secondImage;
#property (nonatomic) BOOL smallMax;
#property (nonatomic, retain) ViewController* pvc;
- (BOOL)testCollision:(CGPoint)point;
- (float)randomFloatBetween:(float)smallNumber bigNumber:(float)bigNumber;
#end
coinView.h
#import "swapView.h"
#class swapView;
#interface coinView : swapView
- (void)count;
- (void)move;
#end
For inheritance, the superclass MUST be inherited.
coinView.h
#import "swapView.h"
#interface coinView : swapView
- (void)count;
- (void)move;
#end
You're both forward declaring and importing ViewController.h in your swapView, which may cause compiler to complain.
swapView.h
#import <UIKit/UIKit.h>
#class ViewController
#interface swapView : UIImageView
.
.
.
#end

Missing '#end' // #end must appear in an objective-c context

This is my code:
#import <UIKit/UIKit.h>
#interface CustomCellArticle: UITableViewCell
#property(nonatomic,retain) IBOutlet UILabel *name;
#end
In first time I received this error:
Missing #end
Expected identifier or '('
in the first of the code, and it required me to add #end in the first to fix it.
the code became like this:
#import <UIKit/UIKit.h>
#end //here the seconde error
#interface CustomCellArticle: UITableViewCell
#property(nonatomic,retain) IBOutlet UILabel *name;
#end
When I add it, I received a new error:
#end must appear in an Objective-C context
I don't know what's happened exactly, please help!
I used the same class in another project and it works fine!
Yes that is from a another header or implementation file already imported beforehand that is missing a #end
It could be a .h or .m file
#end should only come once in a single file.Whats with the top #end.And import all files at the top ?
you may have opened a "{" that is never closed with a "}" before the #end line...
so, the error is not at the #end line... but xcode just find out you are missing a "}" or ")"
Let me show whole file .h and .m file then i can answer well No Problem.
You need to remove first #end from .h file and run you will solve the issue.
Instead of this :
#import <UIKit/UIKit.h>
#end
#interface CustomCellArticle: UITableViewCell
#property (strong, nonatomic) IBOutlet UILabel *name;
#end
Use this :
#import <UIKit/UIKit.h>
#interface CustomCellArticle: UITableViewCell
{
}
#property (strong, nonatomic) IBOutlet UILabel *name;
#end
May this will help you. This is working fine for me.
I have checked also in xcode. You Just need to remove first #end.
If this thing is not working you have some another issue.

Two interface declarations in one file

Here is my .h file:
#import <Foundation/Foundation.h>
#interface ShareOfflineItem : NSObject
#property (strong, nonatomic) id shareService;
#property (strong, nonatomic) NSString *title, *url;
#end
#interface ShareOfflineQueue : NSObject
+(ShareOfflineQueue *)sharedQueue;
-(void)addItemToQueue:(ShareOfflineItem *) item;
-(void)flushQueue;
-(void)saveQueueToDisk;
#end
As you can see nothing more special. But when I import my .h file and try to instantiate ShareOfflineItem I get a linking error:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_ShareOfflineItem", referenced from:
Any ideas?
Use
#class ShareOfflineItem;
#class ShareOfflineQueue;
after the import. This might help.

cannot find protocol declaration custom protocol delegate iphone

Slowly but surely getting this delegation and protocol stuff on iphone but I cannot understand this error.
I have declared my protocol in my first viewcontroller.
In the second viewcontroller i try to add it at the top after i have imported it into the header file and it cannot find it. see my code below.
//SendSMS
#import <UIKit/UIKit.h>
#import "LoginPage.h"
#import "MessageOptions.h"
#protocol SMSProtocol <NSObject>
-(NSString *)postbackType;
#end
#interface SendSMS : UIViewController <UITextViewDelegate, UITextFieldDelegate> {
id<SMSProtocol> delegate;
MessageOptions *messageOptions;
LoginPage *loginPage;
IBOutlet UITextField *phonenumber;
IBOutlet UITextView *smsBody;
IBOutlet UIScrollView *scrollview;
}
#property (nonatomic, retain) id<SMSProtocol> delegate;
-(IBAction)LoadMessageOptions;
#end
Then my second view
#import <UIKit/UIKit.h>
#import "SendSMS.h"
#interface ScheduledSMS : UIViewController <SMSProtocol>{
}
-(IBAction)popBack;
#end
That is surely strange. Have you tried restarting Xcode? Xcode has a habit of not indexing symbols for me when I add new files.
You should also look into how your naming conventions. SendSMS is not really a good class name, more of a action method name. I would go for SendSMSViewController, since that is what it is.
By that it would follow that SMSProtocol should be named SendSMSViewControllerDelegate, since that is what it is.
Methods in a delegate protocol should contain the sender and one of the three words will, did, or should. If not at the very least it should name what it expects to return. -(NSString *)postbackType; should probably be -(NSString *)postbackTypeForSendSMSViewController:(SendSMSViewController*)controller;.

Error when declaring NSManagedObjectContext

I'm trying to create a NSManagedObjectContext object. They error reads as follows:
Expected specifier-qualifier-list
before 'NSManagedObjectContext'
and here is my header file:
#import <UIKit/UIKit.h>
#interface FavouritesViewController : UITableViewController {
NSArray *favourites;
NSManagedObjectContext *context;
}
#property (nonatomic, retain) NSArray *favourites;
#property (nonatomic, retain) NSManagedObjectContext *context;
#end
Anyone know I might be missing here?
Most probably you have forgotten to include the CoreData header in your file. Right after the line #import <UIKit/UIKit.h> you need another line that reads #import <CoreData/CoreData.h>. After this the file should compile fine. Also make sure that you have CoreData in your linked libraries, otherwise you will get runtime errors.
You need to add #class NSManagedObject above your interface directive. This will tell the compiler that NSManagedObject is a real class. You then need to have #import <CoreData/CoreData.h> in your .m file.