I am trying to do mapping with Restkit and created 2 classes as below. I got the following errors:
Unknown type name "Card" in Campaign.h
Unknown type name "Campaign" in Card.h
Property with 'retain (or strong)' attribute must be of object type
... more but similar errors
My question is there a way to achieve below class declaration by re-using class.
Campaign.h
#import "Card.h"
#interface Campaign : NSObject
#property (nonatomic, strong) NSNumber* campaignId;
#property (nonatomic, strong) NSString* title;
#property (nonatomic, strong) Card* card;
#end
Card.h
#import "Campaign.h"
#interface Card : NSObject
#property (nonatomic, strong) NSNumber* cardId;
#property (nonatomic, strong) NSString* name;
#property (nonatomic, strong) Campaign* campaign;
#end
Usually, in headers, you use forward class declarations, in order to avoid imports conflicts. So in Campaign.h, before your interface, you'd have #class Card, and in Card.h, you'd have #class Campaign. This merely tells the compiler that these class exists & are defined somewhere else; that's usually all you need to know in a header.
Just in case someone need it in future. Here my solution:
Campaign.h
#class Card;
#interface Campaign : NSManagedObject
#property (nonatomic, strong) NSNumber* campaignId;
#property (nonatomic, strong) NSString* title;
#property (nonatomic, strong) Card* card;
#end
Campaign.m
#import "Card.h"
#implementation Campaign
...
#end
Card.h
#class Campaign;
#interface Card : NSManagedObject
#property (nonatomic, strong) NSNumber* cardId;
#property (nonatomic, strong) NSString* name;
#property (nonatomic, strong) Campaign* campaign;
#end
Card.m
#import "Campaign.h"
#implementation Card
...
#end
Related
I am getting a build semantic error in XCode when I attempt to build my project. I have 3 NSOperation classes setup to download information from the internet, process it, and send it to the parent view controller, an instance of ViewController. Here is the code for a working class:
#import <Foundation/Foundation.h>
#import "ViewController.h"
#interface ImageGetter : NSOperation
#property (nonatomic) int sid;
#property (nonatomic, retain) ViewController* pvc;
#end
Here is the code for the one that is not working:
#import <Foundation/Foundation.h>
#import "ViewController.h"
#interface CurrentGetter : NSOperation
#property (nonatomic) int sid;
#property (nonatomic, retain) ViewController* pvc;
#end
Error:
ERROR: Unknown type name 'ViewController'; did you mean 'UIViewController'?
Why am I getting this error? I imported ViewController.h in both files and only one is working.
ViewController.h:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>
#import "DataGetter.h"
#import "CurrentGetter.h"
#import "AppDelegate.h"
#interface ViewController : UIViewController <UITabBarDelegate>
{
NSTimer* tmr;
}
#property (nonatomic) float max;
#property (nonatomic, retain) NSDictionary* plist;
#property (nonatomic, retain) NSArray* processingobj;
#property (nonatomic, retain) AVAudioPlayer* intro;
#property (nonatomic, retain) AVAudioPlayer* woop;
#property (nonatomic) float dataDone;
#property (nonatomic) BOOL introDone;
#property (nonatomic) BOOL currentDone;
#property (nonatomic) int newSid;
#property (nonatomic) int newPart;
#property (nonatomic, retain) NSMutableArray* views;
#property (nonatomic) int audioTab;
#property (nonatomic) int currentSid;
#property (nonatomic) BOOL isPlaying;
#property (nonatomic, retain) UIScrollView* partTab;
#property (nonatomic, retain) NSMutableArray* nowPlayingObj;
#property (nonatomic, retain) UINavigationBar* audioNav;
#property (nonatomic, retain) MPMoviePlayerController* player;
#property (nonatomic, retain) UILabel* elapsed;
#property (nonatomic, retain) UILabel* remaining;
#property (nonatomic, retain) UISlider* slider;
#property (nonatomic) BOOL sliderEditing;
#property (nonatomic, retain) UIButton* playBtn;
#property (nonatomic, retain) UITabBar* tabBar;
//Images
#property (nonatomic, retain) UIImage* announcement;
#property (nonatomic, retain) NSMutableArray* seriesBanners;
#property (nonatomic, retain) UIProgressView* prog;
- (void)plistDone;
#end
Try doing a forward declaration of the class in your CurrentGetter header file, like this:
#class ViewController;
#interface CurrentGetter : NSOperation
This tells the compiler that there exists a class called "ViewController." When there are circular dependencies, like when two classes have instances of each other, using forward declarations of the classes resolves the confusion that results.
I am trying to get image in return from the instance method, i am declaring the method in following way, but giving error. I am using NSObject class.
-(UIImage *)getAdImg;
This is giving error that "Expected a type". What does it mean. I normal view controller it is working fine, but in NSObject class it is giving this error. Please guide for the above.
Thanks in advance.
This is my .h file
#import <Foundation/Foundation.h>
#import "JSON.h"
#interface adClass : NSObject
{
NSString *mStrPid;
NSString *mStrAppUrl;
}
#property (nonatomic, strong) NSString *mStrPid;
#property (nonatomic, strong) NSString *mStrAppUrl;
#property (nonatomic, strong) NSMutableArray *mArrAdsDesc;
#property (nonatomic, strong) NSMutableArray *mArrDeviceType;
#property (nonatomic, strong) NSString *mDevice;
#property (nonatomic, strong) NSString *mImgStr;
-(void)iphoneDevice;
-(UIImage *)getAdImg; //(error line)
#end
You have to #import <UIKit/UIKit.h> (where UIImage is declared)
Use this code
-(UIImage *)getAdImg
{
UIImage *image=[[UIImage alloc]init];
image.images=/**An Array of images**/
return ima;
}
Hope it helps!!!
I have two classes.
APPagine.h
#import <Foundation/Foundation.h>
#interface APPagineMedia : NSObject
#property (nonatomic, retain) NSString *Immagine;
#property (nonatomic, retain) NSString *Video;
#end
#interface APPagineDescription : NSObject
#property (nonatomic, retain) NSString *Descrizione;
#end
#interface APPagineSommarioLinee : NSObject
#property (nonatomic, retain) NSString *Description;
#property (nonatomic, assign) int IdLinea;
#end
#interface APPagineSommarioCategorie : NSObject
#property (nonatomic, retain) NSString *Nome;
#property (nonatomic, assign) int DestId;
#property (nonatomic, retain) APPagineSommarioLinee *Linee;
#end
#interface APPagineSommario : NSObject
#property (nonatomic, retain) APPagineSommarioCategorie *Categorie;
#end
#interface APPagine : NSObject
#property (nonatomic, assign) NSString *Layout;
#property (nonatomic, assign) int Indice;
#property (nonatomic, retain) NSString *Titolo;
#property (nonatomic, retain) APPagineMedia *Media;
#property (nonatomic, retain) APPagineDescription *Descrizione;
#property (nonatomic, retain) APPagineSommario *Sommario;
#end
APXmlData.h
#interface APXmlData : NSObject
#property (nonatomic, retain) NSString *Lingua;
#property (nonatomic, assign) float Versione;
#property (nonatomic, assign) long long Timestamp;
#property (nonatomic, retain) APPagine *Pagine;
#property (nonatomic, retain) APCategorie *Categorie;
#property (nonatomic, retain) APCarousel *Carousel;
#end
and finally in my controller interface:
#import "APXmlData.h"
#interface APViewController : UIViewController
{
APXmlData *_XmlData;
}
#end
and in implementation:
_XmlData.Timestamp = 123;
_XmlData.Version = 1.0;
_XmlData.Pagine = [[APPagine alloc] init];
_XmlData.Pagine.Layout = #"a";
_XmlData.Pagine.Indice = 1;
_XmlData.Pagine.Titolo = #"titolo";
//[...]
But,
in when i go to set data to
_XmlData.Pagine = [[APPagine alloc] init];
he returns me a linker error, the classic
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_APPagineDescription", referenced from:
objc-class-ref in APPagine.o
"_OBJC_CLASS_$_APPagineMedia", referenced from:
objc-class-ref in APViewController.o
objc-class-ref in APPagine.o
"_OBJC_CLASS_$_APPagineSommario", referenced from:
objc-class-ref in APPagine.o
ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1
(use -v to see invocation)
My question is: what is correct way to import the classes in my controller?
Should be use #import or #class?
In that order?
What are the classes that require #class or #import?
NOTE
In Build -> Compile Sources, both files are properly configured.
If i remove _XmlData.Pagine = [[APPagine alloc] init]; the apps run well
thanks.
The error you receive is a linker error, not a compiler error, so it looks like your #import was done correctly. Linker errors occur when the program linker cannot find the implementation. I would suggest that you check:
That you have the corresponding #implementation in e.g. APPagine.m
That APPagine.m is included in the project and active for your target in XCode
The problem is your viewController has just
#import "APXmlData.h"
as you are using _XmlData.Pagine = [[APPagine alloc] init]; in your viewController
you should also import APPagine class in your viewController, using
#import "APPagine.h"
The fact that you have a linker error means that the problem is not with your #import or #class declarations. The problem is that your project is missing either the .m files for this class (in case the library includes source that you're supposed to compile yourself) or the library (.a or .dylib or .framework, if the library was already compiled for you). Check the "Build Phases" in your target settings to make sure the necessary files have been included in the project.
It`s probably a very silly mistake, but I've spent over 4 days looking for a solution for this.
It is very simple, I´ve got my MainView.xib and a view called FirstViewController (h/m/xib).
In MainWindow.xib I add a UIViewController and change the class name to FirstViewController and set the Nib name also (altouhg I've tried both ways).
I guess it has to do something with outlets, but I can`t really tell, as I am a newbie developing for iOS, any help wil REALLY help a lot.
Im using XCode 3.2 and interface builder, with SDK 4.3
AppDelegate
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#interface iPadTerritorioV2AppDelegate : NSObject <UIApplicationDelegate> {
IBOutlet UIWindow *window;
IBOutlet UIViewController *navigationController;
NSString *devToken;
NSString *matricula;
NSString *campus;
NSMutableArray *materiasAlumno; //para CCM
NSMutableArray *busqDir; //para CCM
NSInteger agendaBadgeNumber;
NSInteger intramurosBadgeNumber;
NSInteger notificacionesBadgeNumber;
NSInteger mapaBadgeNumber;
NSMutableData *receivedData;
NSMutableDictionary *listData;
BOOL yaSeHizoElPrimerFetchBadges;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UIViewController *navigationController;
#property (nonatomic, retain) NSString *devToken;
#property (nonatomic, retain) NSString *matricula;
#property (nonatomic, retain) NSString *campus;
#property (nonatomic, retain) NSMutableArray *materiasAlumno;
#property (nonatomic, retain) NSMutableArray *busqDir;
#property NSInteger agendaBadgeNumber;
#property NSInteger intramurosBadgeNumber;
#property NSInteger notificacionesBadgeNumber;
#property NSInteger mapaBadgeNumber;
#property (nonatomic, retain) NSMutableData *receivedData;
#property (nonatomic, retain) NSMutableDictionary *listData;
#property BOOL yaSeHizoElPrimerFetchBadges;
- (void)fetchBadges;
#end
FirstViewController.h
#import <UIKit/UIKit.h>
#import "Constants.h"
#import "StringDecoding.h"
#define kConnectionBadgeNotifications 0
#define kConnectionLogin 1
#define kConnectionDevToken 2
#define kCCMindex 0
#define kCSFindex 1
#define kMTYindex 2
#interface FirstViewController : UIViewController {
IBOutlet UISegmentedControl *segmentedCampus;
IBOutlet UITextField *usernameField;
IBOutlet UITextField *passwordField;
IBOutlet UISwitch *remembermeSwitch;
IBOutlet UIButton *loginButton;
UIActivityIndicatorView *loginIndicator;
NSMutableDictionary *listData;
NSMutableData *receivedData;
NSInteger connectionID;
}
#property (nonatomic, retain) UISegmentedControl *segmentedCampus;
#property (nonatomic, retain) UITextField *usernameField;
#property (nonatomic, retain) UITextField *passwordField;
#property (nonatomic, retain) UIActivityIndicatorView *loginIndicator;
#property (nonatomic, retain) UISwitch *remembermeSwitch;
#property (nonatomic, retain) UIButton *loginButton;
#property (nonatomic, retain) NSMutableDictionary *listData;
#property (nonatomic, retain) NSMutableData *receivedData;
#property NSInteger connectionID;
- (IBAction)handleNextClick:(id) sender;
- (IBAction)backgroundClick;
- (IBAction)login: (id) sender;
#end
It sounds like your FirstViewController isn't being retained - if it's not assigned to an outlet anywhere, nothing's retaining it and it'll just disappear. Add a property somewhere (your AppDelegate, perhaps, if that's all you've got) and connect it to the controller:
#property (nonatomic, retain) IBOutlet UIViewController *firstViewController;
I wonder what is wrong with this?
.h file:
typedef enum {
N4LoupeTypeRound,
N4LoupeTypeRectangle,
} N4LoupeType;
#interface N4LoupeLayer : CALayer {
N4LoupeType _type;
UIView *_originalView;
CALayer *_mask;
CALayer *_overlay;
}
#property (nonatomic) N4LoupeType type;
#property (nonatomic, assign) UIView *originalView;
#end
.m file:
#import "N4LoupeLayer.h"
#interface N4LoupeLayer (Privates)
#property (nonatomic, retain) CALayer *mask;
#property (nonatomic, retain) CALayer *overlay;
#end
#implementation N4LoupeLayer
#synthesize type = _type;
#synthesize originalView = _originalView;
#synthesize mask = _mask;
#synthesize overlay = _overlay; // ******I GET THE ERROR HERE*********
#end
No declaration of property 'overlay' found in the interface in N4LoupeLayer.m
You defined the properties for the Privatescategory, but you are trying to synthesize them in N4LoupeLayer.