I have class Person in which I have some properties such as:
#property NSString *name;
#property NSString *email;
#property NSString *phone;
#property UIImage *image;
#property NSInteger *id;
#property NSString *date;
I am saving value like this:
Person *person = [[Person alloc] init];
person.name=#"john";
person.email=#"john#gmail.com";
person.phone=#"1123124";
person.id=#"345";
person.image=[UIImage imageNamed:#"pic.png"];
When I get the value I am able to get all values like name, email, phone etc. But I am not able to get the value of the image. I am getting nil value for image. Why can't I save the value of image in my Person class?
Your error is that your program is unable to find the image named pic.png.
Related
I'm pretty new to Realm and I'm trying to integrate Realm with Firebase. I'm fetching data using realm using a predicate.
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"isArchived == NO AND userId == %#", [User userId]];
RLMResults *dbrecents = [[Recent objectsWithPredicate:predicate] sortedResultsUsingProperty:FRECENT_LASTMESSAGEDATE ascending:NO];
and my firebase data structure,
my Recent object has the exact same values like in firebase structure,
#property NSString *objectId;
#property NSString *userId;
#property NSString *groupId;
#property NSString *initials;
#property NSString *picture;
#property NSString *description;
#property NSString *members;
#property NSString *password;
#property NSString *type;
#property NSString *fullname;
#property NSString *senderName;
#property NSInteger counter;
#property NSString *lastMessage;
#property NSTimeInterval lastMessageDate;
#property BOOL isArchived;
#property BOOL isDeleted;
#property BOOL message_me;
#property NSTimeInterval createdAt;
#property NSTimeInterval updatedAt;
When I'm retrieving data, the dbrecents is empty. How may I fix this?
I'm trying to get data by using core data,but something wrong happen.Here's the picture of my data model:
And code of Feed.h
#interface Feed (CoreDataProperties)
#property (nullable, nonatomic, retain) NSString *rssURL;
#property (nullable, nonatomic, retain) NSString *summary;
#property (nullable, nonatomic, retain) NSString *title;
#property (nullable, nonatomic, retain) NSSet *feedItems;
#end
Firstly,I'm sure I get the data of Feed Table in My FeedList TableViewController.When I tap one row of the table,it should push to the FeedItem TableViewController which contains the data of FeedItem.Here's the code of First Controller:
- (void)cellDidPress:(NSIndexPath *)atIndexPath{
if (atIndexPath.row < self.allFeeds.count) {
RSFeedItemsViewController *itemsVC = [[RSFeedItemsViewController alloc] init];
itemsVC.feed = self.allFeeds[atIndexPath.row];
[self.navigationController pushViewController:itemsVC animated:YES];
}
}
I try to get the FeedItem in my FeedItemsViewController
NSMutableArray *allItems = [[[self.feed feedItems] allObjects] mutableCopy];
And I'm getting the following exception:
po [self.feed feedItems]
<FeedItem: 0x7fe95a484540> (entity: FeedItem; id: 0xd000000007f40002 <x-coredata://918D3499-5129-4D78-8F37-3D8D478FE482/FeedItem/p509> ; data: <fault>)
2016-07-10 14:17:33.176 RSFeedReader[98980:14910776] -[FeedItem allObjects]: unrecognized selector sent to instance 0x7fe95a484540
Should I execute another fetch request to get the data of FeedItem?
Any help is appreciated.
Thanks
Heyo Guys
So I am more or less new to Objective C and got to a problem which I seem unable to solve.
I created a class called "Students" which all have a name surname etc. All those Students are put into a NSMutableArray (before they get created from JSON , that seems to work without a problem though). Then all the names of the students are put into a ListView. Afterwards when a name is clicked (segue passes the object), one should see the details of said student (i.e. his full name, his id, his street).
The problem is that all the string values of the student object seem to get lost.
I checked that all the student object work just fine. I think the problem lies at the #property in my student class.
Any comments and suggestions are appreciated
This is an excerpt of student.h As said only the string values get lost, the int (here the plz value) remains correct
#property (nonatomic, weak)NSString *lastname;
#property (nonatomic, weak)NSString *surname;
#property (nonatomic, weak)NSString *street;
#property (nonatomic, assign)int plz;
EDIT:
Here is where i parse my json.
for (NSDictionary *dic in jsonArray){
NSNumber *identity = [dic valueForKey:#"id"] ;
NSString *firstName = (NSString*) [dic valueForKey:#"first_name"];
NSString *lastName = (NSString*) [dic valueForKey:#"last_name"];
NSString *street = (NSString*) [dic valueForKey:#"street"];
NSNumber *plz = [dic valueForKey:#"plz"] ;
NSString *birth = (NSString*) [dic valueForKey:#"date_of_birth"];
NSArray *bills = dic[#"bills"];
NSArray *hours = dic[#"hours"];
NSLog(#"First %#",firstName);
Student *student = [[Student alloc]initWithLastName:lastName withSurname:firstName withStreet:street withPLZ:plz withOrt:#"Uitikon" withBirthDate:birth withOccupation:#"Schüler"];
[ApprenticeList addObject:student];
}
EDIT 2 :
I found out that the string values get lost even before the segue. All these objects are created in
ViewDidLoad
But in
prepareforsegue
all the values are allready null (except for the int) .So the only place where the student objects work is in
ViewdidLoad
#property (nonatomic, weak)NSString *lastname;
#property (nonatomic, weak)NSString *surname;
#property (nonatomic, weak)NSString *street;
change to
#property (nonatomic, strong)NSString *lastname;
#property (nonatomic, strong)NSString *surname;
#property (nonatomic, strong)NSString *street;
You can also use 'copy'. It will cause the setter for that property to create a copy of the object, otherwise it is identical to strong.
Trying to store value in NSDictionary and retrieve it
Objects
#import <Foundation/Foundation.h>
#class ATTTEstOBJ;
#interface ATTTEst : NSObject
#property (nonatomic, retain) NSString *string1;
#property (nonatomic, retain) NSString *string2;
#property (nonatomic, retain) ATTTEstOBJ *obj1;
#end
#interface ATTTEstOBJ : NSObject
#property (nonatomic, retain) NSString *string3;
#property (nonatomic, retain) NSString *string4;
#property (nonatomic, retain) NSString *array1;
#end
I know it needs to be encoded properly to save and retrieve values.but In this case it is a composite object and I have no idea, how to deal it with.
- (void) encodeWithCoder: (NSCoder *)coder
So TLDR , How to save the composite value into dictionary and retrieve it back
I want to store ATTTest into a dictionary and retrieve it back.
EDIT : Detailed explanation
ATTTEst *test=[[ATTTEst alloc]init];
test.string1=#"a";
test.string2=#"b";
ATTTEstOBJ *obj=[[ATTTEstOBJ alloc]init];
obj.string3=#"c";
obj.string4=#"d";
test.obj1=obj;
NSMutableDictionary *dict=[[NSMutableDictionary alloc]initWithCapacity:3];
[dict setObject:test forKey:#"test"];
NSLog(#"%#",dict);
ATTTEst *tester=[dict objectForKey:test];
NSLog(#"%#",tester.obj1.string3);
IT shows null.as output I want to get the value as c for tester.obj1.string3
ATTTEst *tester=[dict objectForKey:test];
should be
ATTTEst *tester=[dict objectForKey:#"test"];
You have used the object test (instead of the string #"test") as key when retrieving the object. I don't think that
was intentionally.
In order to store them into NSDictionary, you don't need to encode them.
Just do:
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:, attestObject,#"attestObject", attest2Object,#"atttest2" nil];
Where attestObject and attest2Object are the objects you want to store, and strings are their keys.
This has nothing to do with encoding...
This question already has an answer here:
why is my code outputting *nil description*
(1 answer)
Closed 10 years ago.
Here is my custom class:
ClassA.h
#interface ClassA : NSObject<RKRequestDelegate>{
NSString *uri;
NSString *folderUri;
NSInteger idFolder;
NSString *kind;
bool isMine;
CustomUser *owner;
NSMutableArray *usersAdministrators;
NSMutableArray *usersContributors;
NSMutableArray *usersReaders;
NSString *visibility;
NSString *name;
NSString *description;
NSMutableArray *comments;
}
#property (nonatomic,copy) NSString *uri;
#property (nonatomic,copy) NSString *folderUri;
#property (nonatomic,assign) NSInteger idFolder;
#property (nonatomic,copy) NSString *kind;
#property (nonatomic,assign) bool isMine;
#property (retain) DMIUser *owner;
#property (nonatomic,copy) NSMutableArray *usersAdministrators;
#property (nonatomic,copy) NSMutableArray *usersContributors;
#property (nonatomic,copy) NSMutableArray *usersReaders;
#property (nonatomic,copy) NSString *visibility;
#property (nonatomic,copy) NSString *name;
#property (nonatomic,copy) NSString *description;
#property (nonatomic,copy) NSMutableArray *comments;
#end
ClassA.m
#implementation ClassA
#synthesize uri,folderUri,idFolder,kind,isMine,owner,usersAdministrators,usersContributors,usersReaders,visibility,name,description,comments;
-(NSString*)description {
return #"ClassA";
}
#end
Quite simple. But when i try to create new instance of this, like this:
datas = [NSMutableArray array]; // Tried with [[NSMutableArray alloc] init] => same thing
ClassA *classA = [[ClassA alloc] init];
[datas addObject:classA];
NSLog(#"classA = %#",classA);
NSLog(#"datas = %#",datas);
First NSLog returns "ClassA".
Second NSLog returns "datas = ()"
What's wrong here? I always created class like this and i've never had problem like this.
Thanks!
Ok guyzzz i found the problem. It's my attribute:
NSString *description;
Seems that iOs doesn't love that. It conflict with the -description method in NSObject...
After that, i found a similar question here:
Why can't I use "description" as an attribute name for a Core Data entity?
Cheers
if your want to return some value implement method description in the ClassA
- (NSString *)description {
return #"ClassA";
}
You've got everything you need. Are you sure the variable you're assigning to isn't a weak one? All delegate properties are weak, therefore not retaining the object. My guess is that you're doing something like this
someObject.delegate = [[ClassA alloc] init];
NSLog(#"%#", someObject.delegate);
Because the delegate property is weak it doesn't hold onto the variable.
Edit:
This whole answer assumes you are using ARC. If not, disregard.