Archive | Cocoa RSS feed for this section

Objectiveresource does it need rails?

15 Aug

A couple of days back I was looking over my Blog Stats and an interesting search query came up:

objectiveresource does it need rails?

This query got me interested in trying out Objective resource without rails, and technically it should be possible because ObjectiveResource just requires the fetched XML to be in a specific format. So what we can do is create a simple XML document in the same format as Rails out puts its XML. And while we’re at it, let’s create a simple webserver which outputs the XML (honestly I just don’t have Apache working here on my laptop and I seriously can’t be arsed to set it up, and its way too much fun to create a simple Ruby webserver.). So let’s get started!

Continue reading 

Basic Core Animation — iPhone

15 Jun

I’ve previously posted something about Core Animation which was sort of incorrect. I stated that a layer’s delegate must be set in order to have a working animation. Well of course I wasn’t correct. Core Animation requires Animation Blocks which can be ‘created’ with UIView. Well what did I know back then! Here’s the correct code to  get a working implicit core animation working:

[UIView beginAnimations:@"Identifier describing your animation context:nil];
CALayer *layer = self.view.layer;
layer.opacity = 0.1;
layer.transform = CATransform3DMakeScale(.001, .001, .001);
[UIView commitAnimations];

And there we have it :)

Basic CA (Core Animation) for your iPhone

31 May

UPDATE: New post can be found here. Below’s content is incorrect.

After struggling for several hours trying to a get a simple implicit basic animation working on the iPhone I finally managed. What I tried to do is simply scale a view for my fade out animation (basically what your app does  when it quits).

I firstly tried to read in to the documentation provided by Apple, while this documentation certainly provides good content and in dept information about CA but what it truly lacks is decent samples; kinda disappointing. What Apple basically says about implicit animations is that when you do the following:

CALayer *layer = self.view.layer;
layer.position.x = 20;

According to Apple this works. Well I beg the difference. Maybe I’m doing something wrong (although I’ve been checking forums and this seems a pretty common error/problem) or Apple just screws us over! Go a head and try it out if you like, you probably will just see an update of the position of your view, but no animation. What our view’s layer is missing is a delegate so to speak. According to Apple’s documentation the delegate of the layer is the view it belongs to. Well maybe, but I’m sure that ain’t working! What you have to do is set the delegate of the view’s layer to the controller the view belongs to, makes sense?

Here’s the code to transform a controller’s view making it fade out like when you quit the app.

CALayer *layer = self.view.layer;
layer.delegate = self;
layer.opacity = 0.1;
layer.transform = CATransform3DMakeScale(.001, .001, 1.0);

Hope that helps anyone diving in to CoreAnimation like me :)

ObjectiveResource and Rails Relations

27 May

Today I came across the following; I have a model named “Candidate” and Candidates has many regions thru candidates_regions. Now wouldn’t it be handy that when you :GET a candidate you would also include all its relations in the xml or json document? It’s possible! And even by default. All you have to do on the rails side of your code is to make sure the relations get included.
You’d most likely have something in your Ruby code like this:

page.xml { render :xml => @model_name }

In order to also have relations included you can do the following

page.xml { render :text => @model_name.to_xml(:include => [:relation_one, :relation_two]) }

All there’s left now in your objective c interface is to include the relation which holds the interface and add the following:

#import "relationOne"

@interface modelName : NSObject {
    NSString *attribute;
    NSArray *relationOne;
}
@property (nonatomic, retain) NSArray *relationOne;
@end

The relationOne array will now hold objects of type RelationOne with all it’s set attributes, thanks to ObjectiveResource!

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: