Posts

Showing posts from July, 2013

iOS NSDateFormatter and Compare Two Date

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setLocale:[NSLocale currentLocale]]; [dateFormat setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; [dateFormat setDateFormat:@"yyyy/MM/dd"]; NSDate *date = [dateFormat dateFromString:@"2013/5/23"]; NSString *selectionString = [dateFormat stringFromDate:date]; SO Link( http://stackoverflow.com/questions/12721553/get-time-from-nsdate-returns-nil/12721934#12721934 ) Imp Link (http://ios.eezytutorials.com/) The most commonly used date format specifiers are (keep in mind that they are case sensitive): y = year Q = quarter M = month w = week of year W = week of month d = day of the month D = day of year E = day of week a = period (AM or PM) h = hour (1-12) H = hour (0-23) m = minute s = second In general, the number of characters in a specifier determine the size of date field. Let’s use an example to illustrate date formatting. eg. Input date = 2011-05-01 Sunday ...

How to Make REST api call in Objective-C.

We can call using this. NSString * twitterUrl = @ "YourUrlString" ; NSString * resp = [ self makeRestAPICall : twitterUrl ]; and method is -( NSString *) makeRestAPICall : ( NSString *) reqURLStr { NSURLRequest * Request = [ NSURLRequest requestWithURL :[ NSURL URLWithString : reqURLStr ]]; NSURLResponse * resp = nil ; NSError * error = nil ; NSData * response = [ NSURLConnection sendSynchronousRequest : Request returningResponse : & resp error : & error ]; NSString * responseString = [[ NSString alloc ] initWithData : response encoding : NSUTF8StringEncoding ]; NSLog (@ "%@" , responseString ); return responseString ; } 1 2 3 4 @ interface ViewController : UIViewController < NSURLConnectionDelegate > {      NSMutableData * _responseData ; }