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.
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 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
Been programming an iOS/objective-c/cocos2d app. Things have been going fine up until this snag... I should note that it's Objective-C++, ie. .mm files, compiling for the iOS 5.0 simulator.
Basically, I'm only trying to subclass an interface. The error is produced on the #interface line: "Cannot find interface declaration for GameObject"
#import <Foundation/Foundation.h>
#import "CCSprite.h"
#import "cocos2d.h"
#import "Box2D.h"
#import "GameObject.h"
#interface AvalancheBlock : GameObject
{
}
#end
Here's the code for GameObject.h:
#import <UIKit/UIKit.h>
#import "cocos2d.h"
#import "Box2D.h"
#import "b2Body.h"
#import "OhSnowGame.h"
#interface GameObject : CCNode {
#public
b2Body *body;
b2BodyDef *bodyDef;
b2FixtureDef *fixtureDef;
b2PolygonShape *polygonShape;
b2CircleShape *circleShape;
CCSprite *sprite;
int typeTag;
bool markedForDestruction;
}
#property (readwrite, assign) b2Body *body;
#property (nonatomic, assign) b2BodyDef *bodyDef;
#property (nonatomic, assign) b2FixtureDef *fixtureDef;
#property (nonatomic, assign) b2PolygonShape *polygonShape;
#property (nonatomic, assign) b2CircleShape *circleShape;
#property (nonatomic, retain) CCSprite *sprite;
#property (readwrite, assign) int typeTag;
#property (readwrite, assign) bool markedForDestruction;
#property (readonly) int type;
-(id) init;
-(void) initBox2D;
-(int) type;
#end
And GameObject.mm:
#import "GameObject.h"
#implementation GameObject
#synthesize body, bodyDef, fixtureDef, polygonShape, circleShape, sprite, type, typeTag, markedForDestruction;
-(id) init {
if( (self=[super init]) ) {
[self initBox2D];
markedForDestruction = NO;
}
return self;
}
-(void) initBox2D {
bodyDef = new b2BodyDef();
fixtureDef = new b2FixtureDef();
//Initial fixture settings
fixtureDef->density = 1.0f;
fixtureDef->friction = 0.5f;
fixtureDef->restitution = 0.3f;
bodyDef->userData = self;
}
-(int) type {
return 0;
}
#end
If the correct file is being included... then why the error?
Thanks!
SOLVED:
Figured it out... there WAS a circular reference, but I still needed the reference. The solution was to remove the #import "OhSnowGame.h" from GameObject.h, and instead add the directive:
#class OhSnowGame
Learn something new every day.
SECOND UPDATE:
New issue, but very much related.
I have OhSnowGame.mm which includes a "AvalancheGrid.h".
AvalancheGrid.h includes AvalancheParams.h.
In OhSnowGame, I'm referencing both AvalancheGrid and AvalancheParams.
The compiler is throwing a linker error:
"Duplicate symbol AvalancheParams in OhSnowGame.o and AvalancheGrid.o"
But really it doesn't seem like there's any circular reference to me.
If I replace the #import "AvalancheGrid.h" in OhSnowGame.mm with just
#class AvalancheGrid; (and also #class AvalancheParams.h;)
then it doesn't let me reference the properties of those objects like I need to, ie:
avParams.severity = 3; //nope
avParams->severity = 3; //nope
[avParams setSeverity:3]; //nope (with #property severity exposed and synthesized)
I don't understand. How can I avoid the linker error and still access those properties?
I have made a very simple NSObject:
GameSetUpData.h
#interface GameSetUpData : NSObject
#property (readwrite, nonatomic) NSUInteger numberOfPlayers;
#property (strong, nonatomic) NSMutableArray *playerNames;
#property (strong, nonatomic) NSString *gameType;
#property (readwrite, nonatomic) NSUInteger numberOfMinutes;
#property (readwrite, nonatomic) NSUInteger numberOfTurns;
#property (readwrite, nonatomic) CGSize boardSize;
#end
GameSetUpData.m
#import "GameSetUpData.h"
#implementation GameSetUpData
#synthesize numberOfPlayers = _numberOfPlayers;
#synthesize playerNames = _playerNames;
#synthesize gameType = _gameType;
#synthesize numberOfMinutes = _numberOfMinutes;
#synthesize numberOfTurns = _numberOfTurns;
#synthesize boardSize = _boardSize;
#end
This class basically just holds data. I then try to use this object in my viewcontroller:
MainMenu.h
#import <UIKit/UIKit.h>
#class GameSetUpData;
#interface MainMenu : UIViewController
#property (strong, nonatomic) GameSetUpData *gameSetUp;
-(IBAction)tappedNewGame:(id)sender;
-(IBAction)tappedTwoPlayers:(id)sender;
...
MainMenu.m
#import "MainMenu.h"
#import "MJViewController.h"
#import "GameSetUpData.h"
#implementation MainMenu
#synthesize gameSetUp = _gameSetUp;
...
-(IBAction)tappedTwoPlayers:(id)sender {
_gameSetUp.numberOfPlayers = 2;
NSLog(#"number of Players: %d", _gameSetUp.numberOfPlayers);
}
Unfortunately, my NSLog says that numberOfPlayers is equal to 0. What is wrong with my GameSetUpData? I was told that in iOS5 we do not need to call alloc/init or make a dealloc method. Do I still need a -(void)init method in GameSetUpData. Thank you all for your time!
Edit: Please alloc/init your objects -- ARC ONLY deals with release/retain/autorelease. You still need to make an instance of an Object! I apologize for the mis-information. I will make sure to RTFM next time...
Of course you have to alloc/init your object. How should the compiler know when to do that? With ARC you just don't need to retain or release.
Add _gameSetUp = [[GameSetUpData alloc] init]; somewhere.
I want to call a function in a viewController from my appDelegate but with the following code, it doesn't get called. What am I doing wrong?
AppDelegate.h:
#import <UIKit/UIKit.h>
#import "DetailsToTransfer.h"
#class AccountDetailTransferViewController;
#interface AccountDetailTransferAppDelegate : NSObject <UIApplicationDelegate> {
DetailsToTransfer *objDetailsToTransfer;
}
#property (nonatomic, retain) DetailsToTransfer *objDetailsToTransfer;
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet AccountDetailTransferViewController *viewController;
-(void)sendToTransferScreen:(NSArray *)detailsArray;
#end
AppDelegate.m:
....
-(void)sendToTransferScreen:(NSArray *)detailsArray {
[objDetailsToTransfer setLabels:detailsArray];
objDetailsToTransfer = [[DetailsToTransfer alloc]initWithNibName:#"DetailsToTransfer" bundle:nil];
[self.window addSubview:objDetailsToTransfer.view];
}
DetailsToTransfer.h:
#import <UIKit/UIKit.h>
#interface DetailsToTransfer : UIViewController {
NSArray *accountDetailsArray;
UILabel *nameLabel;
UILabel *accountLabel;
IBOutlet UIButton *btnTransfer;
IBOutlet UIButton *btnBack;
}
#property (nonatomic, retain) NSArray *accountDetailsArray;
#property (nonatomic, retain) IBOutlet UILabel *nameLabel;
#property (nonatomic, retain) IBOutlet UILabel *accountLabel;
-(IBAction)sendDetails;
-(IBAction)goBack;
-(void)setLabels:(NSArray *)array;
#end
DetailsToTransfer.m
....
-(void)setLabels:(NSArray *)array {
NSLog(#"Setting Labels");
self.nameLabel.text = [array objectAtIndex:0];
self.accountLabel.text = [array objectAtIndex:1];
}
....
I would like to add that all the properties have been synthesized and that I'm calling the method in the appDelegate properly (i checked using NSLogs)
In AppDelegate.m:
Looks as if you are calling a method on your object before the object has been created. Until you have alloc / init your object, there will be no labels to set text.
Try changing your method to this:
-(void)sendToTransferScreen:(NSArray *)detailsArray {
if (!objDetailsToTransfer) {
objDetailsToTransfer = [[DetailsToTransfer alloc]initWithNibName:#"DetailsToTransfer" bundle:nil];
[objDetailsToTransfer setLabels:detailsArray];
[self.window addSubview:objDetailsToTransfer.view];
}
}
The problem might be that you are trying to set the values on a object that hasn't been created yet. I also provided an if statement to prevent the object from being created multiple times.