I'm developing a chat app and I'm using Parse for backend.
I have a Discussion table to save Discussion between 2 user.
#interface Discussion : PFObject <PFSubclassing>
#property (nonatomic, retain) PFUser * customer;
#property (nonatomic, retain) PFUser * creator;
#property (nonatomic, retain) Quote * quote;
#property (nonatomic, retain) NSDate * lastMessageTime;
#property long messageCount;
#end
I have a Message table to save message.
#interface Message : PFObject <PFSubclassing>
#property (nonatomic, retain) PFUser * sender;
#property (nonatomic, retain) Discussion * discussion;
#property (nonatomic, retain) NSString * content;
#property (nonatomic, retain) PFFile * image;
#property (nonatomic, retain) PFFile * imageThumb;
#property (nonatomic, retain) PFFile * video;
#property (nonatomic, retain) PFFile * videoThumb;
#property (nonatomic, retain) PFGeoPoint * location;
#property (nonatomic, retain) PFFile * sound;
#end
When user chatting, I use cloud code to update lastMessageTime and messageCount.
I want to show a list of people with small label that shows messageCount, and I have a NSTimer to call it automatically each 3.0 seconds.
But when I get new Dicussion, its estimatedData and serverData do not matchs.
I have no idea about this. Please give me your advice.
I have same problem when working on Android Parse SDK.
I think you have edited messageCount on both server side via Cloud Code script and client side via Object-C.
To fix it, you must edit only on client side or server side and sync to another side.
Thanks.
Related
This is my class... I am populating it fine when loading the XML via web service, however when I'm passing the object to another controller I can't get the list of purchase order items into an array I can put into a table.
#interface PORecord (CoreDataProperties)
+ (NSFetchRequest<PORecord *> *)fetchRequest;
#property (nonatomic) int64_t poActivityId;
#property (nullable, nonatomic, retain) NSSet<NSManagedObject *> *receivedRefReasons;
#property (nullable, nonatomic, retain) NSSet<NSManagedObject *> *purchaseOrderItems;
#end
I have an class of core data entity like this,
#interface Answer : SMManagedObject
#property (nonatomic, strong) NSDate *expiresAt;
#property (nonatomic, retain) StudentAssessments * assessment;
#property (nonatomic, retain) Question * question;
#property (nonatomic, retain) Assignment * assignment;
#end
I want to store object of StudentAssessments into Answer object class. So how can i do this?
Its raising error where i do that code for storing like,
[newObjOfAnswer setAssessment:(StudentAssessments *)self.contentObject];
Here self.contentobject is as StudentAsssessments class.
Your help will be appreciated.
I have one problem in converting JSON array to model. I am using JSONModel library.
#protocol PTTemplateModel <NSObject>
#end
#protocol PTProfileTemplateModel <PTTemplateModel>
#end
#protocol PTCategoryTemplateModel <PTTemplateModel>
#end
#interface PTTemplateModel : JSONModel
#property (nonatomic, assign) TemplateType type;
#property (nonatomic, copy) NSString* templateID;
#end
#interface PTProfileTemplateModel : PTTemplateModel
#property (nonatomic, copy) NSString* logoURL;
#property (nonatomic, copy) NSString* title;
#end
#interface PTCategoryTemplateModel : PTTemplateModel
#property (nonatomic, strong) NSString* category;
#end
#interface PTModel : JSONModel
#property (nonatomic, copy) NSString* title;
#property (nonatomic, strong) NSArray< PTTemplateModel>* templates; // PTTemplateModel
Here templates array can have both PTProfileTemplateModel and PTCategoryTemplateModel.
JSON Input:
{"title":"Core","templates":[{"type":0,"templateID":"","logoURL":"", "title":"data"},{"type":1,"templateID":"","category":"DB"}]}
What I need is according to type I have to get CategoryTemplate or ProfileTemplate. But after conversion I am getting just PTTemplateModel type.
I know that I have specified protocol type as PTTemplateModel. But how do I get different type of model according to given data.
I tried:
#property (nonatomic, strong) NSArray< PTTemplateModel>* templates;
#property (nonatomic, strong) NSArray<PTProfileTemplateModel, PTCategoryTemplateModel>* templates;
#property (nonatomic, strong) NSArray< PTTemplateModel , PTProfileTemplateModel, PTCategoryTemplateModel>* templates;
None of them works.
Any suggestions?
Why not try BWJSONMatcher, it helps you work with json data in a very very neat way:
#interface PTModel : NSObject<BWJSONValueObject>
#property (nonatomic, strong) NSString *title;
#property (nonatomic, strong) NSArray *templates;
#end
#interface PTTemplateModel : NSObject
#property (nonatomic, assign) TemplateType type;
#property (nonatomic, strong) NSString *templateID;
#property (nonatomic, strong) NSString *logoURL;
#property (nonatomic, strong) NSString *title;
#property (nonatomic, strong) NSString *category;
#end
In the implementation of PTModel, implement the function typeInProperty: declared in protocol BWJSONValueObject:
- (Class)typeInProperty:(NSString *)property {
if ([property isEqualToString:#"templates"]) {
return [PTTemplateModel class];
}
return nil;
}
Then you can use BWJSONMatcher to get your data model within one line:
PTModel *model = [PTModel fromJSONString:jsonString];
Detailed examples of how to use BWJSONMatcher can be found here.
I have a CoreData-based app. In Core Data, I have an entity called ZSProduction which creates an NSManagedObject subclass called ZSProductionCD. This is the .h file created.
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#interface ZSProductionCD : NSManagedObject
#property (nonatomic, retain) NSNumber * appVersion;
#property (nonatomic, retain) id highlightColour;
#property (nonatomic, retain) NSDate * lastUpdated;
#property (nonatomic, retain) NSString * notes;
#property (nonatomic, retain) NSString * owner;
#property (nonatomic, retain) NSString * productionID;
#property (nonatomic, retain) NSString * productionName;
#property (nonatomic, retain) NSNumber * scenesLocked;
#property (nonatomic, retain) NSNumber * shotNumberingStyle;
#property (nonatomic, retain) NSNumber * sortIndex;
#property (nonatomic, retain) NSNumber * status;
#property (nonatomic, retain) NSString * tagline;
#end
I then subclass this with a class called ZSProduction:
#import <Foundation/Foundation.h>
#import "ZSProductionCD.h"
#interface ZSProduction : ZSProductionCD
#end
The reason for subclassing is that I am likely to add a bunch of methods & possibly other properties. This way, if I make changes to the entity, I can write out a new ZSProductionCD class without affecting what I've done with ZSProduction.
Now here's the problem. I'm using ZSProduction in a view controller. But I'm having a problem with just one of the properties.
In this view controller, I declare a property:
#import "ZSProduction.h"
#interface [...]
#property (strong, nonatomic) ZSProduction *item;
#end
And then later, in a method:
self.productionNameField.text = self.item.productionName;
self.shotNumStyleControl.selectedSegmentIndex = [self.item.shotNumberingStyle intValue];
And that's where it goes wrong. XCode complains:
Property 'shotNumberingStyle' not found on object of type 'ZSProduction *'
Note that it doesn't complain about the productionName property, which works fine.
In the same view controller, if I use:
self.item.shotNumberingStyle = 0;
Then I get the same error. But if I use:
[self.item setValue:0 forKey:#"shotNumberingStyle"];
Then it works fine. Yet I can use:
self.item.highlightColour = [UIColor whiteColor];
with no problem at all. What gives?
Any clues would be appreciated.
Well, I sorted the problem, but I thought I'd leave this here in case someone else has something similar.
I realised that the three properties that were being inherited okay, and were accessible, wee ones I'd created in an earlier version of the ZSProduction class - one that didn't use Core Data (I'm currently refactoring to move from archives to CD).
It turned out that there were old ZSProduction.h and ZSProduction.m files on the disk, in the project subdir - but not in XCode. Seems that XCode was looking at these. The old files were in the root dir for the project, while the newer files were in a subdir (called 'Model'). I deleted the old files, restarted XCode & all is now tickety-boo.
I am trying to learn a bit about the instruments panel in Xcode. I am using ARC. When checking allocations I have been coming up with some abandoned memory it issues. The picture below depicts code from my prepareForSegue method. Every time I tap to perform the segue, memory is allocated and never released. So if I go back and forth between the two viewControllers, the memory keeps climbing and eventually terminates the app. I used the tools to narrow down the problems in the code but am unsure where to go from here. I have seen several examples online about how to identify the problem but not about how to resolve it. So my question is, what is going on here that is causing the app to not release the memory?
properties for viewController 1:
#property (nonatomic, retain) NSMutableArray *recAlbumsArray;
#property (nonatomic, retain) NSMutableArray *titlesArray;
#property (nonatomic, retain) NSMutableArray *timersArray;
#property (nonatomic, retain) NSMutableArray *albumsArray;
#property (nonatomic, retain) NSMutableArray *imagesArray;
#property (nonatomic, retain) NSMutableArray *objsIdArray;
#property (nonatomic, retain) NSArray *imagesDataArray;
#property (nonatomic, weak) NSArray *recAlbumData;
#property (nonatomic, weak) NSArray *albumData;
#property (nonatomic, weak) NSString *albumTitle;
#property (nonatomic, weak) NSString *objId;
properties for viewController 2:
#property (nonatomic, retain) NSMutableArray *album;
#property (nonatomic, weak) NSString *title;
#property (nonatomic, weak) NSString *albumRef;
#property (nonatomic, weak) NSString *objId;
I have tried setting all the properties to nil in a viewDidDisappear method and also tried removing the 1st viewController from the viewController array hierarchy but nothing changed.