"No visible #interface" error with method - objective-c

CJSHWork as a class is defined in CJSHWork.h and CJSHWork.m. In CJSHWork.h I have:
#interface CJSHWork : NSObject
#property (nonatomic, copy) NSString *name;
#property (nonatomic, copy) NSString *title;
#property (nonatomic, copy) NSString *url;
-(id) initWithName:(NSString *)name filename:(NSString *)title content:(NSString *)url;
#end
In CJSHWork.m I have:
- (id) initWithName:(NSString *)name title:(NSString *)title content:(NSString *)url
{
self = [super init];
if (self)
{
_name = name;
_title = title;
_url = url;
}
}
And I have, in CJSHDataController.m,
import "CJSHWork.h"
...
CJSHWork *work = [[CJSHWork alloc] initWithName:#"" title:allWorks[i][1] url:url];
This gets the error "No visible #interface for CJSHWork declares the selector initWithName title url".
What is going on here, and how can I fix it?

Your method name is initWithName:title:content: not initWithName:title:url:

Related

How to reference private instance variable in main.m

I am leaning objective-c, and as shown below in the code, I created an interface with a private instance variable section. In the main.m, a pointer instance variable was created as shown below. what I want to know is how to send a message to one of private instance variable? Something as the following:
[ptr->_address XXX]..IS IT POSSIBLE
2- and how to initialise the private instance variables using
[[xxx alloc] initWithxxx]……IS IT POSSIBLE??
main.m
MeAsImpl *ptr = [[MeAsImpl alloc] initWithCountry:#"DEU" andCity:#"KA" andAddress:#"xyzstrasse7"];
NSLog(#"chip:[ %# ]", ptr->_address);
NSLog(#"chip:[ %p ]", structChipInitializerSegment);
NSLog(#"chip:[ %# ]", structChipInitializerSegment->chipName.self);
NSLog(#"chip:[ %p ]", structChipInitializerSegment->chipName.self);
NSLog(#"chip:[ %p ]", structChipInitializerSegment->numOfTotalChannels);
.h:
#import "ProtocolKidsSchedules.h"
#ifndef MeAsImpl_h
#define MeAsImpl_h
#endif /* MeAsImpl_h */
#interface MeAsImpl : NSObject<ProtocolKidsSchedules> {
id<ProtocolKidsSchedules> _signee;
NSString *_country;
NSString *_city;
NSString *_address;
}
#property (nonatomic, retain) id<ProtocolKidsSchedules> signee;
#property (nonatomic, retain) MeAsImpl *owner;
#property (nonatomic, retain) NSString *country;
#property (nonatomic, retain) NSString *city;
#property (nonatomic, retain) NSString *address;
-(NSString *) signeeOfTheContract: (id<ProtocolKidsSchedules>) signee;
-(id) initWithCountry: (NSString *) country andCity: (NSString *) city andAddress: (NSString *) address;
-(id) initWithOnlyCity: (NSString *) city;
-(id) initWithOnlyAddress: (NSString *) address;
#end
.m
#import <Foundation/Foundation.h>
#import "MeAsImpl.h"
#implementation MeAsImpl
#synthesize country, city, address;
-(BOOL)areChoresCompleted:(BOOL)completed {
return completed;
}
-(BOOL)areHomeWorkCompleted:(BOOL)completed {
return completed;
}
-(BOOL)doDerserveCookies:(BOOL)doDeserve {
return doDeserve;
}
-(NSString *)signeeOfTheContract:(id<ProtocolKidsSchedules>)signee {
return #"Signee is: ";
}
-(id)initWithCountry:(NSString *)country andCity:(NSString *)city andAddress:(NSString *)address {
self->_countery = country;
self->_city = city;
self->_address = address;
return self;
}
-(id)initWithOnlyCity:(NSString *)city {
self->_city = city;
return self;
}
-(id)initWithOnlyAddress:(NSString *)address {
self->_address = address;
return self;
}
#end

'Property not found' in subclass constructor

I have the next code:
GenericClass.h:
#interface GenericClass : NSObject
#property (nonatomic) char tile_inicial;
#property (strong, nonatomic) NSString *color;
GenericClass.m
#implementation GenericClass
-(id)init
{
self = [super init];
return self;
}
- (id)initTodo:(char) tile
{
_tile_inicial = tile;
return self;
}
#end
Animals.h:
#import "GenericClass.h"
#interface Animals : GenericClass
#property (nonatomic) bool fly;
#property (strong, nonatomic) NSString *sound;
#end
#interface Cow : Animals
#property (nonatomic) bool daLeche;
#end
Animals.m
#import "Animals.h"
#implementation Animals
-(id)init
{
self = [super init];
return self;
}
- (id)initAnimal:(bool)fly :(NSString *) sound :(char) tile
{
_fly = fly;
_sound = sound;
self = [super initTodo: tile];
return self;
}
#end
#implementation Cow
-(id)init
{
self = [super initAnimal: false :#"Muu Muu": 'v'];
if (self) {
_daLeche = true;
}
return self;
}
#end
The issue is I would like to call directly from the Cow constructor to any property (for example color or sound) and initialize it.
But if I try to do it without call the parent constructor it returns: "Property not found"
Any idea?
Thanks in advance

Undeclared identifier "isGameCenterAvailable"

Following a book tutorial and seem to run into a snag with the "isGameCenterAvailable" error.
Apparently it is undeclared. Everything else seems to work however so I just need to figure this part out.
Helloworldlayer .m init method
#import <GameKit/GameKit.h>
GameKitHelper* gkHelper = [GameKitHelper sharedGameKitHelper]; gkHelper.delegate = self;
[gkHelper authenticateLocalPlayer];
Class gameKitLocalPlayerClass = NSClassFromString(#"GKLocalPlayer"); bool isLocalPlayerAvailable = (gameKitLocalPlayerClass != nil);
// Test if device is running iOS 4.1 or higher
NSString* reqSysVer = #"4.1";
NSString* currSysVer = [[UIDevice currentDevice] systemVersion]; bool isOSVer41 = ([currSysVer compare:reqSysVer
options:NSNumericSearch] != NSOrderedAscending);
isGameCenterAvailable = (isLocalPlayerAvailable && isOSVer41);
-(void) onLocalPlayerAuthenticationChanged {
[delegate onLocalPlayerAuthenticationChanged];
}
-(void) authenticateLocalPlayer {
GKLocalPlayer* localPlayer = [GKLocalPlayer localPlayer];
if (localPlayer.authenticated == NO) {
[localPlayer authenticateWithCompletionHandler: ^(NSError* error) {
[self setLastError:error]; }];
}
}
Gamekit.h
#import "cocos2d.h"
#import <GameKit/GameKit.h>
#protocol GameKitHelperProtocol
-(void) onLocalPlayerAuthenticationChanged; -(void) onFriendListReceived: (NSArray*)friends; -(void) onPlayerInfoReceived:(NSArray*)players; #end
#interface GameKitHelper : NSObject {
id<GameKitHelperProtocol> delegate; bool isGameCenterAvailable; NSError* lastError;
}
#property (nonatomic, retain) id<GameKitHelperProtocol> delegate;
#property (nonatomic, readonly) bool isGameCenterAvailable; #property (nonatomic, readonly) NSError* lastError;
+(GameKitHelper*) sharedGameKitHelper;
// Player authentication, info
-(void) authenticateLocalPlayer;
-(void) getLocalPlayerFriends;
-(void) getPlayerInfo:(NSArray*)players;
#end
helloworld layer.h
#import "GameKitHelper.h"
#interface helloworldlayer : CCLayer <GameKitHelperProtocol>
{
}
gamekithelper. h
#import "cocos2d.h"
#import <GameKit/GameKit.h>
#protocol GameKitHelperProtocol
-(void) onLocalPlayerAuthenticationChanged; -(void) onFriendListReceived:(NSArray*)friends; - (void) onPlayerInfoReceived:(NSArray*)players; #end
#interface GameKitHelper : NSObject {
id<GameKitHelperProtocol> delegate; bool isGameCenterAvailable; NSError* lastError;
}
#property (nonatomic, retain) id<GameKitHelperProtocol> delegate;
#property (nonatomic, readonly) bool isGameCenterAvailable; #property (nonatomic, readonly) NSError* lastError;
+(GameKitHelper*) sharedGameKitHelper;
// Player authentication, info
-(void) authenticateLocalPlayer;
-(void) getLocalPlayerFriends;
-(void) getPlayerInfo:(NSArray*)players;
#end
The problem is you never actually declare isGameCenterAvailable. To fix this, do this:
//HelloWorldLayer.h
#property (nonatomic) BOOL isGameCenterAvailable;
//HelloWorldLayer.m
#synthesize isGameCenterAvailable = _isGameCenterAvailable;
UPDATE:
To fix the delegate error, try this:
//HelloWorldLayer.h
#property (nonatomic, retain) id<GameKitHelperProtocol> delegate;
//HelloWorldLayer.m
#synthesize delegate;
Hope this helps!

iPhone Super/SubClass Example

I have a superclass Question:
import <Foundation/Foundation.h>
#import "Answer.h"
#interface Question : NSObject {
NSString* qId;
NSString* qTitle;
NSString* qNumber;
NSString* sectionId;
NSString* type;
Answer* answer;
}
#property (nonatomic, retain) NSString* qId;
#property (nonatomic, retain) NSString* qTitle;
#property (nonatomic, retain) NSString* qNumber;
#property (nonatomic, retain) NSString* sectionId;
#property (nonatomic, retain) NSString* type;
#property (nonatomic, retain) Answer* answer;
#end
#import "Question.h"
#implementation Question
#synthesize qId, qTitle, qNumber, sectionId, type, answer;
-(id)init
{
if (self = [super init])
{
// Initialization code here
answer = [[Answer alloc]init];
}
return self;
}
-(void) dealloc{
[answer release];
[super dealloc];
}
#end
I have several types of Question, one example is a Slider Question. I want this class to subclass Question:
#import <Foundation/Foundation.h>
#import "Question.h"
#interface SliderQuestion : Question {
(NSString*) min;
(NSString*) max;
}
#property (nonatomic, retain) NSString* min;
#property (nonatomic, retain) NSString* max;
#end
}
#import "SliderQuestion.h"
#implementation SliderQuestion
#synthesize min, max;
#end
Is this the correct way to subclass? Will SliderQuestion inherit the properties contained within Question?
SliderQuestion* s = [[SliderQuestion alloc]init];
NSLog(#"%#", s.qId); //is this valid
Do you really want min and max to be instances of NSString? It seems that floats would be more appropriate.
Also, scrap the () in (NSString *) to remove the warning/error message.
Finally, this is the appropriate way to subclass. An instance of SliderQuestion will inherit all properties and methods of the Question class (and NSObject as well)
Notice the ( and ) around the NSStrings, you might wanna remove those.

access variable of another class

How to access variables of other class? This is how I implemented it.
#interface Class1 :NSObject {
NSString *Data;
}
#property (nonatomic, retain) NSString *Data;
#implementation Class1
#synthesize Data;
someMethod{
self.Data = #"something";
}
and in Class2 :
#implementation Class2
someMethodOfClass2{
Class1 *c=[[Class1 alloc]init];
[c someMethod];
NSString *str=c.Data;
}
I get c.Data as null in Class2. Am I doing anything wrong here?
-----------myClass1--------------
#interface APIManager : NSObject {
NSString *Data;
}
#property (nonatomic, retain) NSString *Data;
-(void)getData;
#end
#implementation APIManager
#synthesize Data;
-(void)getData{
self.Data=#"response";
}
--------myClass2-------------
#interface Search : NSObject {
}
-(void)searchForItems:(NSString *)query;
#end
#implementation Search
-(void)searchForItems:(NSString *)query {
APIManager *apiManager=[[APIManager alloc]init];
[apiManager getData];
NSLog(#"%#",[apiManager Data]);
}
You should probably use self.Data = #"something" instead of self.Data = "something"
In Objective-C you have to use #"something" instead of "something". Also aren't you missing the variable declaration? In your #interface you should do something like NSString *Data.