I have StoreKit set up in my project and I can get product information from the app store fine, that's all working.
What I'm now trying to do is add an SKProduct as an instance variable in a class of mine, as below:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#interface VideoCell : UITableViewCell
{
IBOutlet UILabel *title;
IBOutlet UILabel *description;
SKProduct *product;
}
#property (retain) IBOutlet UILabel *title;
#property (retain) IBOutlet UILabel *description;
#property (retain) SKProduct *product;
It works fine with just the IBOutlet variables but the SKProduct lines have errors, as follows:
Unknown type name 'SKProduct'
I'm confused because the class name auto-completes but doesn't actually compile...
Any ideas?
It looks like you're missing the import:
#import <StoreKit/StoreKit.h>
Related
So I have been searching in a few hours for why my iPhone app hates me. This is the error I get:
Warning: local declaration of 'speedView' hides instance variable.
Here is my .m file
#implementation MainViewController
#synthesize speedCount;
#synthesize speedView;
#synthesize popoverController;
- (void)setspeedView:(UILabel *)speedView
{
[speedView setText: [NSString stringWithFormat:#"%d",speedCount]];
speedCount = 0;
speedCount++;
}
.h file
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface MainViewController : UIViewController <LoginDelegate,WEPopoverParentView,PopoverControllerDelegate,MainMenuDelegate,MKMapViewDelegate,UIActionSheetDelegate,UIAccelerometerDelegate, CLLocationManagerDelegate>
{
AppDelegate *appDelegate;
IBOutlet MKMapView *userMap;
IBOutlet UILabel *speedView;
CLLocationManager *locationManager;
}
#property (strong, nonatomic) IBOutlet UILabel *speedView;
#property(nonatomic) int speedCount;
I really don't understand why it says that I am hiding the instance variable.
You have a ivar (an instance variable) called speedView.
In your method
- (void)setspeedView:(UILabel *)speedView
speedView is a local variable whose name clashes with the ivar.
If you are using a modern version of the compiler just remove the #synthesize directive.
It will be automatically added by the compiler in this form
#synthesize speedView = _speedView
which will create the ivar _speedView, whose name doesn't clash anymore with the local variable.
Also note that declaring both the instance variable and the property is redundant. The ivar will be automatically created by the (implicit) #synthesize directive.
Here's a "modern" version of your class:
.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface MainViewController : UIViewController <LoginDelegate,WEPopoverParentView,PopoverControllerDelegate,MainMenuDelegate,MKMapViewDelegate,UIActionSheetDelegate,UIAccelerometerDelegate, CLLocationManagerDelegate>
#property (strong, nonatomic) IBOutlet UILabel *speedView;
#property (strong, nonatomic) CLLocationManager *locationManager;
#property (strong, nonatomic) IBOutlet MKMapView *userMap;
#property (strong, nonatomic) AppDelegate *appDelegate;
#property (nonatomic) int speedCount;
.m
#implementation MainViewController
- (void)setspeedView:(UILabel *)speedView {
[speedView setText:[NSString stringWithFormat:#"%d", self.speedCount]];
self.speedCount = 0;
self.speedCount++;
}
Please note:
properties are nice: use them whenever you can
#synthesize is implicit
the implicit version of #sythesize declares a _ivar for the property ivar
always access variables through the getters/setters, i.e. self.ivar, a part from init methods. If you need to access the var directly use _ivar or self->_ivar
As a final remark, this looks a bit weird
self.speedCount = 0;
self.speedCount++;
and it could be replaced with
self.speedCount = 1;
Are you sure it's what you mean? Also, as noted in the comments by others, you are not using the method parameter speedView. That smells bad and you may want to double check your implementation.
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 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
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.
If I add this conditioning compiling flag in my header file, which is a owner of a xib file, the xib file cannot read the IBOutlet and show as missing. And gives warnings.
In runtime it works fine. Did anybody experience the same problem?
/* MFMessageComposeViewControllerDelegate is available in iOS 4.0 and later. */
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
#interface SendMoneyResponseVC : UITableViewController
<UINavigationControllerDelegate, MFMessageComposeViewControllerDelegate,
MFMailComposeViewControllerDelegate, UIActionSheetDelegate>
#else
#interface SendMoneyResponseVC : UITableViewController
<UINavigationControllerDelegate,
MFMailComposeViewControllerDelegate, UIActionSheetDelegate>
#endif
{
IBOutlet UITableView *sendMoneyTableVC;
IBOutlet UITableViewCell *refNumRemittanceCell;
IBOutlet UILabel *refNumLabel, *refNumValueLabel, *refNumInfoLabel;
IBOutlet UITableViewCell *refNumDomesticCell;
IBOutlet UILabel *domesticInfoLabel, *feeAndReferenceLabel;
IBOutlet UITableViewCell *shareRefNumCell;
IBOutlet UIButton *shareRefNumButton;
NSString *referenceNumber, *recipient, *currency, *mtoName;
float amount, fee;
int sendMoneyType;
UIAlertView *smsAlertView;
}
#property (nonatomic, retain) UITableView *sendMoneyTableVC;
#property (nonatomic, retain) UITableViewCell *refNumRemittanceCell;
#property (nonatomic, retain) UILabel *refNumLabel, *refNumValueLabel, *refNumInfoLabel;
#property (nonatomic, retain) UITableViewCell *refNumDomesticCell;
#property (nonatomic, retain) UILabel *domesticInfoLabel, *feeAndReferenceLabel;
#property (nonatomic, retain) UITableViewCell *shareRefNumCell;
#property (nonatomic, retain) UIButton *shareRefNumButton;
#property (nonatomic, retain) NSString *referenceNumber, *recipient, *currency, *mtoName;
#property float amount, fee;
#property int sendMoneyType;
- (IBAction) didPressShareButton;
#end
Have you tried restructuring your code in a way which is equivalent to the compiler, but is less likely to confuse Interface Builder? Something like this:
#interface SendMoneyResponseVC : UITableViewController
<UINavigationControllerDelegate,
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
MFMessageComposeViewControllerDelegate,
#endif
MFMailComposeViewControllerDelegate,
UIActionSheetDelegate>
{ ... }
#end
This way there will be only one #interface/#end pair.
what is the reason for doing this? Unless you want to compile with an outdated SDK you should get rid of this.
Interface Builder doesn't preprocess your files, so it will see two #interfaces and one #end.
And interface builder can't parse something like this.