I have a file called ToDoList.h and XYZToDoItem.h. XYZToDoItem.h contains the following:
#import <Foundation/Foundation.h>
#interface XYZToDoItem : NSObject
#property NSString *itemName;
#property BOOL completed;
#property (readonly) NSDate *creationDate;
#end
ToDoList.h contains the following:
#import "ToDoList.h"
#interface ToDoList ()
#property NSMutableArray *toDoItems;
#end
#implementation ToDoList
- (void) loadInitialData {
XYZToDoItem *item1 = [[XYZToDoItem alloc] init]; //<- ERROR
}
the error message in the last line in the latter class say the following:
1-use of undeclared identifier XYZToDoItem
2-use of Declared identifier item
please have look at the image posted below, it shows the contents and the error message in the class
please let me know why I am getting this error and how to solve it?
image
Related
I have a problem in Xcode.I am trying to copy one NSString into other one but is not working.
The original NSString pageTitle is on the RestViewController:
This is my RestViewContoller.h:
#import <UIKit/UIKit.h>
#import "Restaurant.h"
#interface RestViewController : UIViewController
#property (strong, nonatomic) IBOutlet UILabel *TitleLabel;
#property (strong, nonatomic) IBOutlet UILabel *DescriptionLabel;
#property (strong, nonatomic) IBOutlet UIImageView *ImageView;
#property (nonatomic, strong) Restaurant *DetailModal;
#property (nonatomic, strong) NSString *pageTitle;
#property (nonatomic, strong) NSString *pageDescription;
#end
The NSString I want to save the data is on the RestViewController:
#property (nonatomic, strong) Restaurant *DetailModal;
but is a Restaurant class type.
My Restaurant class is:
Restaurant.h:
#import <Foundation/Foundation.h>
#interface Restaurant : NSObject
#property (nonatomic, copy) NSString *title;
#property (nonatomic, copy) NSString *desc;
#property (nonatomic, copy) NSString *image;
- (instancetype)init:(NSString *)title descripiton:(NSString *)description image:(NSString *)image;
#end
Restaurant.m:
#import "Restaurant.h"
#implementation Restaurant
- (instancetype)init:(NSString *)title descripiton:(NSString *)description image:(NSString *)image {
self = [super init];
if (self != nil) {
self.title = title;
self.desc = description;
self.image = image;
}
return self;
}
#end
And finally the place where I want to copy this NSStrings is my RestViewController.m:
#import "RestViewController.h"
#import <QuartzCore/QuartzCore.h>
#interface RestViewController ()
#end
#implementation RestViewController
- (void)viewDidLoad {
[super viewDidLoad];
_pageTitle = #"Test";
_DetailModal.title = _pageTitle;
NSLog(#"_DetailModal.title: %#", _DetailModal.title);
}
#end
The problem is when I see the result of the
NSLog(#"_DetailModal.title: %#", _DetailModal.title);on the console,
it puts me:2016-11-21 11:42:05.407 MadEat[3667:104028]
_DetailModal.title: (null)
What can I do? I know I have a low level of Xcode, but I need your help please. Thank you very much.
Initailize the instance of DataModel First.
Then proceed with assignment
_DetailModal = [[DetailModal alloc] init:_pageTitle descripiton:#"Desc" image:#"image"];
There is a instance method defined already to do the task.
After this also you can alter the value by
_DetailModal.title = #"title_of_yours"
If you have to use detailmodal, you must alloc the restaurant class object (detailmodal). Then only the objects can be used.
detailmodal=[[restaurant alloc]init];
detailmodal.title=_pagetitle;
Before you can use a object, you have to create it first.
DetailModal *detailModal = [DetailModal new];
That way the object will be created and values stored to the class properties will be reserved.
Try:
_DetailModal.title = [[NSString alloc] initWithString: _pageTitle];
(Did not test this)
plz chek you _DetailModal is not nil
if it's nil then
first you need to alloc the memory for you DetailModal Class object
like this
DetailModal *detailModal = [DetailModal new];
then after set the value you want
detailModal.title = _pageTitle;
i am new to ios and objected C.
I am trying to encode a url, bit i am getting the error
/Users/zupportdesk/Desktop/MyIOSApps/ZDticketSystem/ZDticketSystem/ViewController.m:313:52:
No visible #interface for 'NSString' declares the selector
'URLEncodeUsingEncoding:'
#import "ViewController.h"
#import "AppDelegate.h"
#import "ApplicationEnvironmentURL.h"
#import "AFNetworking/AFNetworking.h"
#import "HHAlertView/HHAlertView.h"
#import "MBProgressHUD/MBProgressHUD.h"
#import "AppDelegate.h"
#interface ViewController ()<UITextFieldDelegate, UIActionSheetDelegate> {
ApplicationEnvironmentURL *applicationEnvironment;
NSString *BASEURL;
NSString *global_profileId;
AppDelegate *delegate;
}
#property (nonatomic, strong) NSString *username;
#property (nonatomic, strong) NSString *password;
#end
#implementation ViewController
--- defaults methods here
- (void)setupProfileidURL:(NSString *)profileToken {
NSString *encoded_profileToken = [profileToken URLEncodeUsingEncoding:NSUTF8StringEncoding];
NSString *user_login_url = [applicationEnvironment get_user_api_url];
BASEURL = [[user_login_url stringByAppendingString:#"Account/GetProfileDetails?profileToken="] stringByAppendingString:encoded_profileToken];
NSLog(#"Base URL: %#", BASEURL);
}
I am calling the method like this
[self setupProfileidURL:profileToken];
View Holder header file
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (weak, nonatomic) IBOutlet UITextField *tv_username;
#property (weak, nonatomic) IBOutlet UITextField *tv_password;
#end
I want to implement this https://madebymany.com/blog/url-encoding-an-nsstring-on-ios . can some one help me with this url encoding.
You are getting this message
No visible #interface for 'NSString' declares the selector
'URLEncodeUsingEncoding:'
because URLEncodeUsingEncoding is a method which is defined in a Category and you are not using that category in your class thats why you are getting this message.
Also CFURLCreateStringByAddingPercentEscapes is deprecated from iOS so in place of it you can use stringByAddingPercentEncodingWithAllowedCharacters
Below is an example of of your function
- (void)setupProfileidURL:(NSString *)profileToken {
NSString *encoded_profileToken = [profileToken stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSString *user_login_url = [applicationEnvironment get_user_api_url];
BASEURL = [[user_login_url stringByAppendingString:#"Account/GetProfileDetails?profileToken="] stringByAppendingString:encoded_profileToken];
NSLog(#"Base URL: %#", BASEURL);
}
Also as per the #Larme comment you can create a category and use it in your application by importing it.
Even after reading the other posts like this one, I have not been able to find the duplicate interface definition, nor have I been able to fix this using any previous method mentioned on StackOverflow.
I tried turning #import <UIKit/UIKit.h> into: #import "Ukit.h" like another post suggested, along with everything else, and still nothing.
How else can I try and fix this?!
#import <UIKit/UIKit.h>
#interface STEDataSheet : NSObject { // error found: Duplicate interface definition for class 'STEDataSheet'
NSMutableArray *_rows;
NSString *_dataSheetPath;
NSString *_documentsPath;
NSString *_persistenceName;
}
#property (atomic) NSString *sheetId; // error found: property has a previous declaration
#property (atomic) NSArray *rows; // error found: property has a previous declaration
#property (atomic) NSUUID *latestLoadId; // error found: property has a previous
try this:
#import <UIKit/UIKit.h>
#interface STEDataSheet : NSObject { // error found: Duplicate interface definition for class 'STEDataSheet'
NSMutableArray *rows;
NSString *_dataSheetPath;
NSString *_documentsPath;
NSString *_persistenceName;
}
#property (atomic) NSString *sheetId; // error found: property has a previous declaration
#property (atomic) NSArray *rows; // error found: property has a previous declaration
#property (atomic) NSUUID *latestLoadId; // error found: property has a previous
maybe you can find something difference about the property:
like this:
#property (atomic) NSArray *rows;
_rows
self.row
Hope it helps;
I'm adapting This tutorial to my app, and I've got it boiled down to one last error, which is stopping me in my tracks. The program is unable to find a property in another file, but that property is clearly defined. Here is the code in question:
The actual error line:
for (DTContact *dtc in _dtContact.contact) {
the .h for the file, and items in question:
#import <UIKit/UIKit.h>
#class XMLTestViewController;
#class DTCXMLResponse;
#interface XMLTestController : UIViewController{
UIWindow *window;
XMLTestViewController *viewController;
DTCXMLResponse *_dtContact;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet XMLTestViewController *viewController;
#property (nonatomic, retain) DTCXMLResponse *dtContact;
#property (nonatomic, retain) IBOutlet UIButton *mybutton;
-(IBAction)buttonClicked;
#end
It's having issues with the _dtContact.contact. It can't find the contact in the file DTCXMLResponse. Here is the .h file and the section of the .m:
.h
#import <Foundation/Foundation.h>
#interface DTContactXMLResponse : NSObject {
NSMutableArray *_contact;
}
#property (nonatomic, retain) NSMutableArray *contact;
#end
.m
#import "DTCXMLResponse.h"
#implementation DTContactXMLResponse
#synthesize contact = _contact;
- (id)init {
if ((self = [super init])) {
self.contact = [[NSMutableArray alloc] init];
}
return self;
}
#end
So theres that. As you can see, I have 'contact' propertied in the DTCXMLResponse.h, and linked in the .m.
This error usually points out that Xcode can not recognize your symbol.
I can assume this is DTContact.
Try to insert this in your .h file:
#import DTContact.h
Its not relevant to ur case but I was getting the same error. I googled for a solution but the problem was in my code. I was using different class object as I was copy pasting similar snippet of code in my project. So here is the problem that I had for the same error :
For my classA , I had some code snippet like :
ManagedObjectOfClassA * managedObjectOfClassA = [NSEntityDescription insertNewObjectForEntityForName:#"ManagedObjectOfClassA" inManagedObjectContext:managedObjectContext];
managedObjectOfClassA.somePropertyA = sameValue; //somePropertyA is an attribute of ManagedObjectOfClassA
And similar code for class B :
ManagedObjectOfClassA *managedObjectOfClassB = [NSEntityDescription insertNewObjectForEntityForName:#"ManagedObjectOfClassB" inManagedObjectContext:managedObjectContext];
managedObjectOfClassB.somePropertyB = someValue;////somePropertyB is an attribute of ManagedObjectOfClassB
If u look closely, the mistake was in assigning the right entities to the corresponding objects in class B.
So the problem is in code of class B. And the correct code would be :
ManagedObjectOfClassB *managedObjectOfClassB = [NSEntityDescription insertNewObjectForEntityForName:#"ManagedObjectOfClassB" inManagedObjectContext:managedObjectContext];
managedObjectOfClassB.somePropertyB.someValue;
I hope that helps someone.
I'm adapting This tutorial to my app, and I've got it boiled down to one last error, which is stopping me in my tracks. The program is unable to find a property in another file, but that property is clearly defined. Here is the code in question:
The actual error line:
for (DTContact *dtc in _dtContact.contact) {
the .h for the file, and items in question:
#import <UIKit/UIKit.h>
#class XMLTestViewController;
#class DTCXMLResponse;
#interface XMLTestController : UIViewController{
UIWindow *window;
XMLTestViewController *viewController;
DTCXMLResponse *_dtContact;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet XMLTestViewController *viewController;
#property (nonatomic, retain) DTCXMLResponse *dtContact;
#property (nonatomic, retain) IBOutlet UIButton *mybutton;
-(IBAction)buttonClicked;
#end
It's having issues with the _dtContact.contact. It can't find the contact in the file DTCXMLResponse. Here is the .h file and the section of the .m:
.h
#import <Foundation/Foundation.h>
#interface DTContactXMLResponse : NSObject {
NSMutableArray *_contact;
}
#property (nonatomic, retain) NSMutableArray *contact;
#end
.m
#import "DTCXMLResponse.h"
#implementation DTContactXMLResponse
#synthesize contact = _contact;
- (id)init {
if ((self = [super init])) {
self.contact = [[NSMutableArray alloc] init];
}
return self;
}
#end
So theres that. As you can see, I have 'contact' propertied in the DTCXMLResponse.h, and linked in the .m.
This error usually points out that Xcode can not recognize your symbol.
I can assume this is DTContact.
Try to insert this in your .h file:
#import DTContact.h
Its not relevant to ur case but I was getting the same error. I googled for a solution but the problem was in my code. I was using different class object as I was copy pasting similar snippet of code in my project. So here is the problem that I had for the same error :
For my classA , I had some code snippet like :
ManagedObjectOfClassA * managedObjectOfClassA = [NSEntityDescription insertNewObjectForEntityForName:#"ManagedObjectOfClassA" inManagedObjectContext:managedObjectContext];
managedObjectOfClassA.somePropertyA = sameValue; //somePropertyA is an attribute of ManagedObjectOfClassA
And similar code for class B :
ManagedObjectOfClassA *managedObjectOfClassB = [NSEntityDescription insertNewObjectForEntityForName:#"ManagedObjectOfClassB" inManagedObjectContext:managedObjectContext];
managedObjectOfClassB.somePropertyB = someValue;////somePropertyB is an attribute of ManagedObjectOfClassB
If u look closely, the mistake was in assigning the right entities to the corresponding objects in class B.
So the problem is in code of class B. And the correct code would be :
ManagedObjectOfClassB *managedObjectOfClassB = [NSEntityDescription insertNewObjectForEntityForName:#"ManagedObjectOfClassB" inManagedObjectContext:managedObjectContext];
managedObjectOfClassB.somePropertyB.someValue;
I hope that helps someone.