Robustness Principle

Recently, while working on an iOS app I was writing client code that requests a web service.
It was a GET request.
According to the service documentation, the request accepted some parameters.
But when adding these parameters to the request did not yield expected response, I requested the API developer to shed some light.
The developer provided me with a cURL representation of the request and I found that parameters were passed in the –data option of the request.
While this is allowed, it is not the recommended approach – passing data in the body of the GET request.

This answer on stack overflow quotes from the RFC2616 – Hypertext Transfer Protocol — HTTP/1.1 and describes that the approach is not forbidden. So it’s allowed to send entity-body with a HTTP GET request.
Whereas this answer describes that the GET body has no semantic meaning.
Also, this post suggests avoiding it simply because it’s not expected. It also talks about the Robustness Principle that wikipedia summarizes as Be conservative in what you do, be liberal in what you accept from others.

In our client-server scenario, this translates to following:
The client should request the server in a way that is concise and conforms to the specifications but the server should be open to any kind of request as long as it is semantically correct.

Coming back to our iOS client side code, I found out from an answer on google groups that while this was possible through the cURL representation from the terminal, iOS would not allow it.

Finally, I had to ask the API developer to make some changes and the request was changed to POST.

By akshay1188

Bottom Aligning UILabels

Sometimes we feel a need to bottom align UILabels. Especially when two labels have varying font size.
I tried to make a simple UILabel category for that purpose.
Let us see what happens when we add UILabels of different font sizes adjoining each other.
The code for adding two labels before aligning their bottoms will be:

    UILabel* name = [[UILabel alloc]initWithFrame:CGRectMake(20, 20, 150, 30)];
	[name setText:@"Title1Font25"];
	[name setFont:[UIFont systemFontOfSize:25]];
	[name setBackgroundColor:[UIColor clearColor]];
    [name sizeToFit];
	[self.view addSubview:name];

    UILabel* name1 = [[UILabel alloc]initWithFrame:CGRectMake(name.frame.origin.x + name.frame.size.width, 20, 150, 30)];
	[name1 setText:@"Title2Font20"];
	[name1 setFont:[UIFont systemFontOfSize:20]];
	[name1 setBackgroundColor:[UIColor clearColor]];
    [name1 sizeToFit];
	[self.view addSubview:name1];

These labels will look like this:

UILabels-before-bottom-aligning

UILabels before bottom aligning

Adding this extra line after the above code:

[name1 setFrame:CGRectMake(name1.frame.origin.x, [name1 topAfterBottomAligningWithLabel:name], name1.frame.size.width, name1.frame.size.height)];

The labels after bottom aligning will look like:

UILabels after bottom aligning

UILabels after bottom aligning(Guide for reference)

The UILabel category for bottom aligning UILabels can be found at UILabel(BottomAlign)

For a better understanding of UIFont and what are ascenders and descenders there’s a nice description here.

By akshay1188