Receiver 'SMClient' for class message is a forward declaration - ios

I'm trying to add StackMob to my project. It says to create an SMClient instance after having dragged the SDK to the project, checking 'create groups for..' and adding to target. I followed these steps.
However, when I'm creating my SMClient and SMCoreDataStore instances, it gives me an error of Receiver 'SMClient' for class message is a forward declaration and the same for SMCoreDataStore. Here's my code:
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#class SMClient;
#class SMCoreDataStore;
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) NSManagedObjectModel *managedObjectModel;
#property (strong, nonatomic) SMCoreDataStore *coreDataStore;
#property (strong, nonatomic) SMClient *client;
#end
And part of my .m:
#import "AppDelegate.h"
#import "StackMob.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.client = [[SMClient alloc] initWithAPIVersion:#"0" publicKey:#"YOUR_PUBLIC_KEY"];
self.coreDataStore = [self.client coreDataStoreWithManagedObjectModel:self.managedObjectModel];
return YES;
}
I already cleaned the project, imported the relevant header files, but it still gives that error.
Any ideas?

This might be happening because you forgot to import the classes.
Add it on your .m:
#import "SMClient.h"
#import "SMCoreDataStore.h"

Related

Cannot find delegate defined in another header

I have a very simple problem, yet because it's so simple, I can't find anything wrong with it to fix.
ListSelectorUtility.h
#import <UIKit/UIKit.h>
#protocol ListSelectorDelegate <NSObject>
- (void) returnValueString:(NSString *)value requestID:(long)requestID;
#end
#interface ListSelectorUtility : UITableViewController
#property (strong, nonatomic) NSString *data;
#property (weak, nonatomic) id<ListSelectorDelegate> delegate;
#property (nonatomic) long requestID;
#end
UpdateProperty.h
#import <UIKit/UIKit.h>
#import "ListSelectorUtility.h"
#interface UpdateProperty : UITableViewController <ListSelectorDelegate>
#property (nonatomic, strong) NSDictionary *data;
#end
There's an error on the #interface UpdateProperty : UITableViewController <ListSelectorDelegate> saying that No type or protocol named 'ListSelectorDelegate'. Why is this happened? How to solve this? Thanks.
EDIT: oh, and when I do CMD+click on the <ListSelectorDelegate>, it brings me straight up to the ListSelectorDelegate declaration. That means the IDE (supposedly) can find it.
set property of delegate (strong) on ListSelectorUtility.h
#property (strong, nonatomic) id<ListSelectorDelegate> delegate;
may bey problem of that because if it is week then dealloc by ARC and call the delegate method on ListSelectorUtility.h on your pass the data and values
[self.delegate returnValueString:obj_StringValue requestID:obj_requestID];
And finally this delegate method declare in UpdateProperty.h,
- (void) returnValueString:(NSString *)value requestID:(long)requestID
{
//---------
//Your Code
//---------
}

iOS - shortcut to synthesize properties using extension

Let's say i have a class definition header file like this :
#import <UIKit/UIKit.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (readonly, strong, nonatomic) SomeObject *managedObject;
#end
instead of defining the #synthesize on managedObject to create the getters/setters a friend of mine told me i can do the following header definition using a class extension to do the synthesis more cleanly:
#import "TSPAppDelegate.h"
#interface TSPAppDelegate () //notice the class extension here
#property (strong, nonatomic) SomeObject *managedObject; //this will already be synthesized since its an extension
#end
Could some one explain how this works using the extensions ?
I think your friend is incorrect. You have to #synthesize to have the getters/setters implemented for you

Property not found although it's in the header

I have one view and one View Controller. I am trying to have a reference to View Controller from the view.
PlusCalendarView.h
#interface PlusCalendarView : TSQCalendarView
#property (nonatomic, strong) UIViewController *initialVC;
#end
ViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
[self setUpCalendarView:self.myCalendarView];
self.myCalendarView.initialVC = self; // ERROR: Property initialVC not found on object of type "PlusCalendarView"
}
How come it cannot find initialVC property?
Update:
ViewController.h
#import <UIKit/UIKit.h>
#import <TimesSquare/TimesSquare.h>
#interface PlusCalendarView : TSQCalendarView;
#end
#interface ViewController : UIViewController
#property (nonatomic, strong) NSCalendar *calendar;
#property (strong, nonatomic) IBOutlet PlusCalendarView *myCalendarView;
#end
The problem is that you're declaring PlusCalendarView in ViewController.h AND PlusCalendarView.h. You should remove the #interface declaration from ViewController.h.
Instead, add #class PlusCalendarView in ViewController.h then #import "PlusCalendarView.h" in ViewController.m

Defining a delegate in a UIView/UIViewController relationship

I have a subclassed UIView called TargetView that is contained in a UIViewController called MainViewController. I want to set MainViewController as the delegate for TargetView so that MainViewController can receive messages from the child view (TargetView).
In my MainViewController (UIViewController) header I have the following:
#import <UIKit/UIKit.h>
#import "TargetView.h"
#class TargetView;
#interface MainViewController : UIViewController <TargetViewDelegate>
#property (strong, nonatomic) IBOutlet TargetView *target;
#property (strong, nonatomic) IBOutlet UILabel *lblResults;
#end
When I set the TargetViewDelegate in the interface declaration, it shows up in code completion so it knows that it's there, but then the build fails with the message: can't find protocol declaration..."
In my TargetView (UIView) class I have the following:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "MainViewController.h"
#protocol TargetViewDelegate
#required
-(void)receivedTargetTap;
#end
#interface TargetView : UIView{
id<TargetViewDelegate> delegate;
}
#property (nonatomic,strong) NSString *lblResults;
#property (nonatomic,weak) id<TargetViewDelegate> delegate;
#end
Creating custom delegates is uncharted territory for me. Can anyone tell me what I'm doing wrong? Thanks!
I believe your TargetView.h should be :
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#protocol TargetViewDelegate <NSObject>
#required
-(void)receivedTargetTap;
#end
#interface TargetView : UIView
#property (nonatomic, strong) NSString *lblResults;
#property (nonatomic, weak) id<TargetViewDelegate> delegate;
#end
MainViewController.h :
#import <UIKit/UIKit.h>
#import "TargetView.h"
#interface MainViewController : UIViewController <TargetViewDelegate>
#property (strong, nonatomic) IBOutlet TargetView *target;
#property (strong, nonatomic) IBOutlet UILabel *lblResults;
#end
From your code, you must add <NSObject> after your protocol definition, and remove the MainViewController.h import in your TargetView class.
I think there might be a problem with your import statements in both .h files.
Why do you reference MainViewController.h from TargetView.h? It seems like you don't need it. On the other hand, you should remove the forward declaration of #class TargetView in MainViewController.h, and the simple #import "TargetView.h" should be enough.
After that, you'll also need to implement the required - (void)receivedTargetTap;, otherwise the compiler will complain again that the TargetViewDelegate is not fully implemented.

#class and #import on another view controller, what does it means?

I am newbie on Xcode, and trying to figure out more about coding in xcode.
So, I am trying to learn more about models (models operation) on objective C.
I am confused in #Class declaration in PhotoViewController.h and .m Files
as you may see below, I already imported Photo.h on appdelegate.m and also PhotoViewController.m files
the objective from my tutorial is PhotoViewController.m files can recognize self.photo.filename
But, why it has to add #Class and #property in PhotoViewController.h files?
isnt #import command is already enough? what does #Class means and why it has to include #property too?
note : I tried to put a comment (//) on #class , but xcode tell me that photo property not found, and when I put added comment (//) on property
PhotoViewController.m file also messed up with unrecognized photo property.
I dont quite understand, the use of #class and #import at the same time, plus declaring #property photo
here is Photo.m
#import "Photo.h"
#implementation Photo
-(id)init
{
self = [super init];
return self;
}
#end
and
Photo.h
#import <Foundation/Foundation.h>
#interface Photo : NSObject
#property (weak, atomic) NSString *title;
#property (strong, nonatomic) NSString *detail;
#property (strong, nonatomic) NSString *filename;
#property (strong, nonatomic) NSString *thumbnail;
#end
Appdelegate.m
#import "AppDelegate.h"
#import "FeedTableViewController.h"
#import "ProfileViewController.h"
#import "FavoritesViewController.h"
#import "Photo.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
Photo *photo= [[Photo alloc]init];
photo.title = #"Demo Photo";
photo.detail = #"This is a demo photo";
photo.filename = #"demo.png";
photo.thumbnail = #"demo-thumb.png";
return YES;
}
#end
PhotoViewController.h Files
#import <UIKit/UIKit.h>
#class Photo;
#interface PhotoViewController : UIViewController
#property (weak, nonatomic) NSString *imageFileName;
#property (weak, nonatomic) NSString *imageTitle;
#property (strong, nonatomic) Photo *photo;
#end
PhotoViewController.m Files
#import "PhotoViewController.h"
#import "UIImageView+AFNetworking.h"
#import "Photo.h"
#implementation PhotoViewController
-(void)viewDidLoad {
// self.title = self.imageTitle;
UIImageView *imageView = [[UIImageView alloc] init];
[imageView setImageWithURL:[UIImage imageNamed:self.photo.filename]];
imageView.frame = CGRectMake(10,10,300,300);
[self.view addSubview:imageView];
UILabel *imageTitleLabel = [[UILabel alloc] init];
imageTitleLabel.text = self.imageTitle;
imageTitleLabel.frame = CGRectMake(11,320,300,40);
[self.view addSubview:imageTitleLabel];
}
#end
#class Photo defines the existence of class Photo to PhotoViewController.h allowing you to declare photo property.
Photo property is later used in PhotoViewController.m to to access the instance variable photo like this self.photo or [self photo]
You could have put #import "Photo.h" in your PhotoViewController.h but it is cleaner this way :)
#property
It is for replacement of getter method, whenever you want to get the value you have to declare that variable as property, so that need not to write getter method separately,
you should implement #synthesize also in Photo.m, #synthesize will work as setter method.

Resources