Titanium Properties API usage - titanium

I'm new to Titanium Properties API. I'm getting a weird error when using setObject() method.
Following is my code.
Titanium.App.Properties.setObject(view.idAttr, view);
Where view.idAttr is a string acting as a key for this property and view is a View type object. Upon calling above method, I get following message.
2012-09-14 17:47:25.947 SumMeUp[14033:4a03] *** -[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '[object TiUIView]' of class 'TiUIViewProxy'. Note that dictionaries and arrays in property lists must also contain only property values.
I couldn't understand this behavior. If anyone knows a solution to, please reply.
Thanx

setObject() is meant for objects only, not for views.
A object would be something you write yourself in JavaScript.
Even if it could, it would be bad behaviour of the app to store it in a property. Remember the property is being stored cross-session. So if you want something stored, store data there to generate the view later again, not the view itself. Also saves a lot of memory!

Related

insertDataforTableName returns wrong object type

I'm building out some new functionality in my app which is essentially just old code copied for a new class type. Before it was creating and displaying vehicles, and now it's creating and displaying books, however it's not behaving as expected.
I want to persist the data, so here is the code which creates a new ManagedObject, which should return a pointer to the object:
vehicle = [[MyCoreDataManager sharedManager] insertDataforTableName:#"MyVehicle"];
This line returns an object of type MyVehicle, which is what I want. MyVehicle is a class which inherits from NSManagedObject and has its own methods which are immediately used after inserting.
Now I want to have the same exact arrangement, except with a MyBook object. However, when I run:
book = [[MyCoreDataManager sharedManager] insertDataforTableName:#"MyBook"];
The above line of code returns an object of type NSManagedObject, which is wrong because I can't access the MyBook methods because it's an NSManagedObject and not a MyBook. I even tried type casting, but it doesn't work. The fact that it is an NSManagedObject and not a MyBook is causing my app to crash with an unrecognized selector sent to instance exception because I am trying to call a method which is not recognized by the object at runtime. Your thoughts are appreciated.
My understanding of the problem is that somehow the MyBook class is not properly declared or has some subtle issue in its .h or .m file which is causing it not to link up at runtime. Or some kind of problem with the .xcdatamodeld entity definition.
Rob Mayoff was correct to ask:
Does the definition of the "MyBook" entity in the data model specify "MyBook" as its class?
Because in this case it did not. If you ever want to create a new entity in your data model, be sure to specify the actual class that it is associated with in the right hand toolbar. It's pretty easy to miss this step, if you ask me.

Play Framework 2.1.1: bindFromRequest() returns the correct data but ignores all data pertaining to relations

I have a form that is supposed to create an entity of type Load, but for some reason, doesn't seem to be actually passing or seeing any of the data related to associations of the entity (load.user, load.client, etc). This all used to work fine but stopped working at some point during a bunch of refactoring (that didn't change any of the fields in any of the models). Now all of the forms in my website have broken the same way and I have no clue where to even look to start fixing it.
From the view, I submit the form for a new Load, printing out the data everywhere I can along the way. Printing out the data being sent to the server before it's sent shows all the data is there like it should be. Printing out Form.form(Load.class).bindFromRequest() in the controller shows the form's data contains everything needed, for example, the value user.id=1 is in the data. However, there is also a validation error saying that the user is missing. How can this be?
Form(of=class models.Load, data={ a bunch of stuff, user.id=1, a bunch more stuff}, value=None, errors={=[ValidationError(,Logged in user is missing or invalid.,[])]})
The validation error is being generated by public String validate() in the Load class, which is simply checking if(user==null) and returning that string if it is. I should note that every form that submits multiple entities (for example, submitting a Dock and then also the Dock's Location) only saves the main entity (in this example, the Dock) and ignores all others (the Dock's Location is never saved, even though Dock cascades in the model to also save the Location). All of our form fields are labelled correctly, this code did used to work at some point before it mysteriously stopped working!
So why did all of my forms suddenly stop correctly dealing with anything but the main model for the form? It is as if they cannot even "see" the data contained in bindFromRequest(). If I print out a variable in the validation method of Load, such as this.status, it prints the correct thing. But if I try to print something like this.user.id or this.client.id I get a null pointer error. Where is the code in Play that actually interprets the data (user.id=1) and turns it into the User associated with the Load, and how could it be breaking?
Edit: Also, yes, I did try "play clean", it was the first thing I tried since usually it fixes weird errors like these! But this time, no dice.
Edit2: I'm including the html from the form, in case it is helpful.
<input type="text" id="user_id" name="user.id" value="1" class="idfield">
Edit3: The only change I made during the refactoring that might have influenced this is that I had to make some setter methods like Load.setBroker() because the ones that are supposedly generated by Play didn't work. For example, load.broker=aBroker would not have set the Load's Broker before, so I had to make a public void setBroker(Broker broker) method in Load. Does Play use the auto-generated setters to bind the data? Could overwriting them cause problems?
Whoops, I figured it out. It was the setters I had written. Some of them were set to private purely by mistake, and apparently this was preventing Play from setting the values when binding the data. Changed them all to public and the mystery error vanished.

Class / object logic

How would you solve this? When the app starts, four objects of a class are created. These objects have names you know because you named them yourself. From a viewController you can access these objects and call a method (which they all got) which creates a UILocalNotification. (So in the end you've got four notifications running.)
Two questions:
How do you name the notifications (differently)? As far as I know is it not possible to access the object name to use the string as name when creating the notification? (Which would be the best solution?)
When the notifications are fired, how do you access/cancel them from another viewController when you don't know the names?
Thank you!
Set tags for all objects, and set same tags for notifications, they generate.

Objective-c, passing NSURLConnection result to a View Controller

Long time reader, first time poster here.
I'm creating a test app that creates a NSURLConnection and then displays the result on an UILabel.
I am presently using a Notification Center observer, which fires a notification from within connectionDidFinishLoading to wait for the connection to complete successfully, before I look for the result.
However, what I am struggling to conceptualize is where to store the response data so that I can access it from my View Controller and post the result to the UILabel. (Or from anywhere other than an instance of my Connection Class, for that matter.)
I don't want to post directly to the UILabel from connectionDidFinishLoading. I need a way to decide what I will do with the response later - so my Connection Class stays generalized.
I need a better way to save the response data somewhere, where I can reference it after the instance of the Connection Class has terminated.
Ideally, it should be somewhere that I can have multiple instances of the Connection Class open, and access each response in turn as I need them. This eliminates the potential to just create a variable in my View Controller or somewhere else more global and dump the response to it.
Any ideas on what design patterns could/should be used here would be greatly appreciated!
My suggestions for you to start with are :
Make a singleton class. I will have a property NSDictionary * info or NSArray *infoList; You will have acces to the same data from wherever the app. Update the property, post the notification, access the property from the viewController.
Store the info into a plist/file. Serialize the information, or save plain stream. Whatever you like.Thus after you finish writing to the file, post the notification, read from the file from anyplace within the app.
In both cases if you want multiple connections i suggest going for the factory design Pattern.

Attribute called 'description' causes crash

I just started playing with Core Data.
I created an entity called Task with a property called Description. I opened Interface Builder and I added Core Data Entity view.
Picked my entity, property and tried to build the application. After clicking on "Add" button it crashed with EXC_BAD_ACCESS.
After I've renamed this attribute to 'desc' it works fine.
Can anyone explain me why is this happening? Is 'description' some kind of reserved word in Core Data or something?
description is ann Objective-C property used for debugging and goes all the way down to Core Foundation, which has a corresponding CFDescription function. You should just name that property something else.
It's a method with a particular purpose in Cocoa, and Core Data dislikes it being overridden. More here.