UA-17470720-3

Jump to content


Photo
- - - - -

Parse.com -- manipulating and displaying Date and geoPoint Info

web-services sections cells data-definitions

  • Please log in to reply
7 replies to this topic

#1 Glenn Toole

Glenn Toole

    Starting Out

  • STV 4.0 Std
  • Pip
  • 7 posts
Reputation: 1
Good

Posted 16 February 2013 - 07:37 AM

Hi,
Forgive a question from a noob :) STV is such a great product -- and it attracts us novices because of the ease of use.

I'm having trouble manipulating information for date parse.com date cells and geopoints.

I've been able to successfully manage manipulation of number and text properties within an object on Parse (and display in a cell)
But I can't update the date object or a geopoint object

I started with basic manipulation and updating of text or number info by simply using ....myObject setValue mystring_or_number forKey. When I get into the nested geoPoint or Date NSDictionary, it won't let me update it.

I finally even tried having Sensible Tableview automatically set up a date picker and cell to display the Date and GeoPoint properties -- and I get update warnings (I also get these when I set the object properties programatically).

Any help would be appreciated.
Here is basic code from the Parse.com example with a modification -- which tries (and fails) to simply add the date and geopoint cells:


SCParseComDefinition *taskDef = [SCParseComDefinition definitionWithClassName:@"Task" columnNamesString:@"name;description;category;active;myDate" applicationId:@"my application ID" restAPIKey:@"my restAPIKey"];

SCPropertyDefinition *descPDef = [taskDef propertyDefinitionWithName:@"description"];
descPDef.type = SCPropertyTypeTextView;
// mydate and geo code lines follow
SCPropertyDefinition *dateDef = [taskDef propertyDefinitionWithName:@"myDate"];
dateDef.type = SCPropertyTypeDate ;

SCPropertyDefinition *geoDef = [taskDef propertyDefinitionWithName:@"myGeo"];
geoDef.type = SCPropertyTypeAutoDetect;


Ideally, I'd like to also simply update the Geo Object programatically -- by creating a geopoint and using setObject.... or setValue.. for a latitude or longitude within a point.

Thanks!
Glenn

#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 18 February 2013 - 12:00 PM

Hi Glenn and welcome to STV! :)

So let me make sure I correctly understand this: In the above code, your problem is that "description" is being correctly updated but not "myDate"?

#3 Glenn Toole

Glenn Toole

    Starting Out

  • STV 4.0 Std
  • Pip
  • 7 posts
Reputation: 1
Good

Posted 18 February 2013 - 08:10 PM

Hi Tarek,
Thanks... You've got an awesome product. I know just enough to appreciate how much power it has under the hood.

I think the answer to your question is "yes". If I let STV provide a date picker, the values in the parse dashboard are not updated and i get a console warning of "unable to update object"
If I programmatically try to set a date or geo value with "setValue" or "setObject" I have similar problems. I have no problem setting values programmatically or with the text/number editor in the view.. Thanks...

#4 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 20 February 2013 - 12:21 PM

Hi Glenn,

Thanks a lot for all your complements :)

We've done some testing and I can confirm that there is an issue between STV and parse.com with these kind of objects. We'll study this further and release a fix ASAP (please let me know if you have an urgent deadline).

Thank you one more time.
  • cometlinear likes this

#5 Glenn Toole

Glenn Toole

    Starting Out

  • STV 4.0 Std
  • Pip
  • 7 posts
Reputation: 1
Good

Posted 20 February 2013 - 07:28 PM

Hi Tarek,
Thanks -- I'm glad I'm not going crazy.. ;-) It's not a short term panic. I'm working on some workarounds -- and I'll let you know my progress.
Thanks,
Glenn

#6 Glenn Toole

Glenn Toole

    Starting Out

  • STV 4.0 Std
  • Pip
  • 7 posts
Reputation: 1
Good

Posted 08 May 2013 - 07:19 AM

Hi Tarek,

Has this issue been fixed in 3.2.0?

I gave it a quick try -- and I still get an error in the console that the webservice for parse.com encounters an error when it tries to send the date back to parse from a date picker.



#7 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 08 May 2013 - 08:56 AM

Hi Glenn,

 

I apologize for not giving you an update about this. Things have been going crazy here with upgrading servers after the 3.2.0 release.

 

We've actually contacted Parse regarding the above issue, and it turns out that their web service expects the Date and GeoPoint values to be delivered in a special proprietary format. For example, for NSDate, they require that the value be sent in a dictionary that looks like this:

 

{
  "__type": "Date",
  "iso": "2011-08-21T18:02:52.249Z"
}

 

Now since STV is just sending the date to Parse as a string (which is the standard way), the date commit fails. STV actually provides several ways to get around this (listed in the order of how easy to implement):

 

a. This is the simplest: you can just store the date value as a simple String in Parse (by choosing the field's type as String instead of Date). STV will then be able to automatically convert this string into NSDate and work with it as a regular date. Similarly, a GeoPoint can be stored as two string or number fields: latitude and longitude. 

 

b. STV offers you the ability to change a property's value right before it's committed by using the willCommitBoundValue cell action. This way, you can convert the NSDate value to Parse's proprietary format before it gets sent. Your code should look something like this:

 

SCWebServiceDefinition *myWebServiceDef = ...;
SCPropertyDefinition *datePropertyDef = [myWebServiceDef propertyDefinitionWithName:@"date"];
datePropertyDef.cellActions.willCommitBoundValue = ^NSObject*(SCTableViewCell *cell, NSIndexPath *indexPath, NSObject *value)
{
  if([value isKindOfClass:[NSDate class]])
  {
    // First convert NSDate to ISO string date
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"];  // ISO 8601 format
    NSString *dateString = [dateFormatter stringFromDate:(NSDate *)value];
 
    // Next, set value to Parse's proprietary dictionary
    value = @{ @"__type":@"Date", @"iso":dateString };
  }
  
  return value;
}
 
// Of course we also need to convert the dictionary back to NSDate when we receive it from Parse
datePropertyDef.cellActions.didLoadBoundValue = ^NSObject*(SCTableViewCell *cell, NSIndexPath *indexPath, NSObject *value)
{
  if([value isKindOfClass:[NSDictionary class]])
  {
    NSString *dateString = [value valueForKey:@"iso"];
 
    // convert dateString to NSDate
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"];  // ISO 8601 format
    value = [dateFormatter dateFromString:dateString];
  }
 
  return value;
}

 

c. Finally, we can create a new STV data store just for Parse, which can be called SCParseComStore. The new store would automatically do all these conversions for you. We did not have time to implement such a store in 3.2.0 because we needed more time to research all Parse.com data types and their proprietary formats. We will most probably be implementing it in the upcoming STV release.

 

Please let me know if you have any questions or need any further help.



#8 Glenn Toole

Glenn Toole

    Starting Out

  • STV 4.0 Std
  • Pip
  • 7 posts
Reputation: 1
Good

Posted 08 May 2013 - 11:15 AM

Hi Tarek,

 

Thanks for the response.  I've already implemented "a" in the last few months -- and will take a crack at "b" -- a good suggestion.

I would also encourage you on the "c" option.  I am biased -- but I see a lot of movement toward more utilization of backend as a service..

 

As always.... STV is a great product and is really helping speed the development process.  Keep up the nice work!

Glenn







Also tagged with one or more of these keywords: web-services, sections, cells, data-definitions

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users