I am new to iphone development. I have this code in the delegate.h section:
#import <UIKit/UIKit.h>
#import <objc/Object.h>
#class Learning1ViewController;
#interface Greeter: NSObject<UIApplicationDelegate>
{
}
-(void)greet;
#end
#include <stdio.h>
#implementation Greeter
-(void) greet
{
printf ("Hello, World!\n");
}
#include <stdlib.h>
int main(void)
{
id myGreeter;
myGreeter=[Greeter new];
[myGreeter greet];
[myGreeter free];
return EXIT_SUCCESS;
}
#end
#interface Learning1AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
Learning1ViewController *viewController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet Learning1ViewController *viewController;
#end
When i compile i get this error:
ld: duplicate symbol _main in /Users/ianbennett/Desktop/iphone development/Learning1/build/Learning1.build/Debug-iphonesimulator/Learning1.build/Objects-normal/i386/Learning1AppDelegate.o and /Users/ianbennett/Desktop/iphone development/Learning1/build/Learning1.build/Debug-iphonesimulator/Learning1.build/Objects-normal/i386/main.o
command/Developer/platforms/iphoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1
I have seen that other people have had similar errors and that it might be to do with my library but im not really sure how to fix it.
You have defined the main() function twice (looks like it's defined in Learning1AppDelegate.m and main.m
Thanks for the error message
You have defined the same function main in 2 places
The files are
main
Learning1AppDelegate
You can only define a function in one place - so you have to choose
Related
I am a beginner in objective C and I am using the following code
I am using xcode6
// Car.h
#import <Foundation/Foundation.h>
#interface Car : NSObject {
NSString *simple_name; //This is private
#property int mssp; //Cant use #property Error illegal visibility specification
}
-(void) sayHi:(NSString*)msg ;
#end
Any suggestions on why I am getting this error ?
Move #property int mssp; out of the brackets:
// Car.h
#import <Foundation/Foundation.h>
#interface Car : NSObject {
NSString *simple_name; //This is private
}
#property int mssp;
-(void) sayHi:(NSString*)msg ;
#end
I am trying to fix this compiler error:
Receiver type X for for instance message is a forward declaration.
The App is a Universal iOS app with a storyboard. This problem involves three VC Classes.
From my RootTableViewController, the app can segue to either InfoScaledViewController or SubListViewController.
Compilation fails because of the following error.
RootTableViewController.m:309:10: Receiver type 'InfoScaledViewController' for instance message is a forward declaration
There is no corresponding error a few lines above it, where identical procedure is done with SubListViewController.
These two lines are:
SubListViewController *destCntrlr =
(SubListViewController *)segue.destinationViewController;
and
InfoScaledViewController *destCntrlr =
(InfoScaledViewController *)segue.destinationViewController ;
If I comment out the line that causes this compilation error and set a breakpoint at that position, you can see from the following screenshot, why I am puzzled by the error.
As you can see, I have used #import "InfoScaledViewController.h" in RootTableViewController.m and #class InfoScaledViewController
in RootTableViewController.h
I have read many answers given to address this error. None of the have helped.
File: InfoScaledViewController.h
#import <UIKit/UIKit.h>
#import "BNRDynamicTypeManagedLabel.h"
...
#interface InfoScaledViewController : UIViewController <UIAlertViewDelegate> {
BOOL pushedForImport;
...
}
#property (nonatomic, assign) BOOL pushedForImport;
...
#end //InfoScaledViewController.h
File: InfoScaledViewController.m
#import "InfoScaledViewController.h"
...
#implementation InfoScaledViewController
#synthesize pushedForImport;
#end // InfoScaledViewController.m
File: SubListViewController.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#interface SubListViewController : CoreDataTVC < UITableViewDelegate,UITableViewDataSource,UIAlertViewDelegate, AddRecipeDelegate,EditRecipeDelegate,UISearchBarDelegate,UITextFieldDelegate> {
//...
BOOL isNewPush;
}
//...
#property (nonatomic,assign) BOOL isNewPush;
//...
#end //SubListViewController.h
File: SubListViewController.m
#import "SubListViewController.h"
//...
#implementation SubListViewController
//...
#synthesize isNewPush;
#end
File: RootTableViewController.h
#import <UIKit/UIKit.h>
...
// #import "InfoScaledViewController.h"
#class InfoScaledViewController;
#class SubListViewController;
//...
#interface RootTableViewController : CoreDataTVC
< NameViewDelegate,UIAlertViewDelegate, UITableViewDataSource, UITableViewDelegate >
{
//...
SubListViewController *subListViewController;
InfoScaledViewController* infoViewController;
//...
}
#property (nonatomic, strong) SubListViewController *subListViewController;
#property (nonatomic, strong) InfoScaledViewController * infoViewController;
...
#end
File: RootTableViewController.m
#import "RootTableViewController.h"
//...
#import "SubListViewController.h"
#import "InfoScaledViewController.h"
//...
#implementation RootTableViewController
#synthesize subListViewController = _subListViewController;
#synthesize infoViewController = _infoViewController;
//...
#end // RootTableViewController.m
THE PLACE in RootTableViewController.m WHERE ERROR OCCURS IS BELOW
Note: Xcode "recognizes" both SubListViewController and InfoScaledViewController Classes, giving both names the same color.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:#"SLVC"]) {
SubListViewController *destCntrlr
= (SubListViewController *)segue.destinationViewController;
[destCntrlr setIsNewPush:YES]; // NO ERROR HERE
...
}else if ([segue.identifier isEqualToString:#"INFO"]){
InfoScaledViewController *destCntrlr
= (InfoScaledViewController *)segue.destinationViewController ;
[destCntrlr setPushedForImport:(sender == nil) ? YES : NO]; // ERROR HERE breakpoint is here
...
}
else if ([segue.identifier isEqualToString:#"ADDCATEGORY"]){
...
}
}
I'm getting errors for the appdelegate.h: "expected identifier or {" and "Parse issue: Missing #end".
I've tried everything I can think of to fix this. I've checked the headers and #imports. I've moved all the classes into a new project thinking there was something wrong in the build settings. I even reinstalled Xcode to no avail. Here's the app delegate.h
#import <UIKit/UIKit.h>
#import "MainViewController.h"
#interface AppDelegate : UIResponder <UIApplicationDelegate> {
UIWindow *window;
MainViewController *viewController;
NSMutableArray *savedBookmarksArray;
}
#property (nonatomic) IBOutlet UIWindow *window;
#property (nonatomic) IBOutlet MainViewController *viewController;
#property (nonatomic) NSMutableArray *savedBookmarksArray;
#end
Every class that references the app delegate said the file could not be found. The .m is included in the Compile Sources. Anyone know how to fix this?
main.m
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
MainViewController.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "DDWebView.h"
#class AboutTableViewController;
#interface MainViewController : UIViewController <UIActionSheetDelegate, UIAlertViewDelegate, UIWebViewDelegate, UIPopoverControllerDelegate, UIScrollViewDelegate, UIGestureRecognizerDelegate> {
}
#end
I solved the issue. I had an import as #import "AppDelegate" instead of #import "AppDelegate.h" in one of my other headers.
Thanks for all your help guys!
..
I had a similar issue but it turned out that i accidentally declared the #interface inside the .m file and that screwed around with it. Once i removed it from the .m file it worked.
My project works fine on simulator but wouldn't build on real device after adding:
#synthesize extraView=_extraView;
It seems that this line somehow hides file header. Tried "Clean" - no change.
I've used #property and #synthesize many times before and haven't seen anything like this.
I'm planning to rewrite extraView handling but I'm asking just out of curiosity if someone has experienced similar error.
Platform:
XCode 4.0.1
4.2.1 Ipad
File header:
//
// MediaBook.h
// Dolphin
//
// Created by Handymood on 11-5-22.
// Copyright 2011 __Hanydmood__. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "SinglePage.h"
#import "LayerInfo.h"
#import "MediaBookXMLParser.h"
#import "GlobalSet.h"
#import "UIComponentBase.h"
#import "IndexPageInfo.h"
#import "IndexPage.h"
#import "TopBar.h"
#import "BottomBar.h"
#import "DolphinUIWebLayer.h"
#import "MediaBookBase.h"
#import "ColorUtil.h"
#import "DolphinUICategory.h"
#import "UICategoryUnit.h"
#import "ImageInfoBox.h"
#import "Gallery.h"
#import "Calendar.h"
#class SinglePage;
#class LayerInfo;
#class MediaBookXMLParser;
#class GlobalSet;
#class UIComponentBase;
#class IndexPageInfo;
#class IndexPage;
#class TopBar;
#class BottomBar;
#class DolphinUIWebLayer;
#class MediaBookBase;
#class ColorUtil;
#class DolphinUICategory;
#class UICategoryUnit;
#interface MediaBook : MediaBookBase <UIScrollViewDelegate>
{
UIImageLayer *backGroundImage;
UIView *bgView;
BottomBar *bottomBar;
DolphinUIWebLayer *webLayer;
DolphinUICategory *categoryLayer;
UIActivityIndicatorView *activityIndicator;
UIInterfaceOrientation preOrientation;
NSTimer *objQueMagTimer;
float previous_scroll_pos;
BOOL bar_status_hidden;
float top_bar_ori_y;
float bottom_bar_ori_y;
BOOL scroll_block_signal;
int screen_direction;//0:vertical 1:horizontal
BOOL webLayerOn;
BOOL categoryOn;
BOOL changingExtraView;
}
#property UIInterfaceOrientation preOrientation;
#property (nonatomic, retain) UIView *extraView;
-(void) initWithGlobalSet:(GlobalSet *) inGlobalSet;
-(void) initBook:(NSString *)configXmlAdd curOrientation:(UIInterfaceOrientation)interfaceOrientation;
-(void) initBookContent;
-(void) notificationSelector:(NSNotification *) notification;
-(void) statusBarAnimationTrigger;
-(void) layoutAdjustWithOrientation:(UIInterfaceOrientation)interfaceOrientation
orientaionType:(NSString *) inOrientationType;
-(void) closeCategoryLayer;
-(void) reset;
-(void) showExtraView:(NSString *)name;
-(void) hideExtraView;
#end
Screenshot of build errors:
I've used #property and #synthesize many times before and haven't seen any similar.
Adding following to interface declaration solved the problem:
UIView *_extraView;
Thanks to mja for the tip.
It is my GameEngine.h:
#import <Foundation/Foundation.h>
#import "GameArray.h";
#interface GameEngine : NSObject {
GameArray *gameButtonsArray;
}
#property (nonatomic, retain) GameArray *gameButtonsArray;
And this is my GameArray.h:
#import <Foundation/Foundation.h>
#import "MyAppDelegate.h";
#interface GameArray : NSObject {
NSMutableArray *gameButtonsArray;
}
#property (nonatomic, retain) NSMutableArray *gameButtonsArray;
It keep prompt my "expected specifier-qualifier-list" error i my GameEngine.h, and error said that "expected specifier-qualifier-list before 'GameArray'", what's going on?
This is the best practice.
GameEngine.h
#import <Foundation/Foundation.h>
#class GameArray;
#interface GameEngine : NSObject {
GameArray *gameButtonsArray;
}
#property (nonatomic, retain) GameArray *gameButtonsArray;
Then in GameEngine.m
#import "GameEngine.h"
#import "GameArray.h"
#implementation GameEngine
//...
#end
This prevents circular references wherein one header imports a second header which imports the first which imports the second and so on in an endless cycle.
Lose the semi-colon on line 2 in your .h file
If removing the unnecessary semicolons does not fix your problem, most likely MyAppDelegate.h imports GameEngine.h creating a circular dependency between the GameEngine.h and GameArray.h. Try removing the #import "GameArray.h" from GameEngine.h and replacing it with:
#class GameArray;
Also add
#import "GameArray.h"
to GameEngine.m below the import of GameEngine.h