Tuesday, August 02, 2011

Create JSON Object Manually without using SBJSON in iOS SDK

+(NSString *)createJSONString:(NSDictionary *) dictionary

{

NSArray *jsonKeyArray = [dictionary allKeys];

NSArray *jsonKeyValue = [dictionary allValues];

NSString *jsonString = @"{";

for (int j=0; j<[jsonKeyArray count ]; j++) {

NSDictionary *dictFromArray = [jsonKeyValue objectAtIndex:j];

NSArray *keyArray = [dictFromArray allKeys];

jsonString = [NSString stringWithFormat:@"%@\"%@\":",jsonString, [jsonKeyArray objectAtIndex:j]];

NSArray *valueArray = [dictFromArray allValues];

// to check its empty dictionary

if ([keyArray count] != 0) {

for (int i = 0; i<[keyArray count];i++) {

if (i == 0) {

jsonString =[NSString stringWithFormat:@"%@{ \"%@\": \"%@\", ",jsonString,[keyArray objectAtIndex:i],[valueArray objectAtIndex:i]];

}//to check lost element of single dictionary

else if((i == [keyArray count]-1) ) {

if (j != [jsonKeyArray count]-1) {

// to check whether last element combined dictionary

jsonString =[NSString stringWithFormat:@" %@ \"%@\":\"%@\" },",jsonString,[keyArray objectAtIndex:i],[valueArray objectAtIndex:i]];

}else

{

jsonString =[NSString stringWithFormat:@" %@ \"%@\":\"%@\" }",jsonString,[keyArray objectAtIndex:i],[valueArray objectAtIndex:i]];

}

}else {

jsonString =[NSString stringWithFormat:@"%@ \"%@\":\"%@\", ",jsonString,[keyArray objectAtIndex:i],[valueArray objectAtIndex:i]];

}

}

}else {

if (j != [jsonKeyArray count]-1) {

jsonString =[NSString stringWithFormat:@"%@{},",jsonString];

}else

{

jsonString =[NSString stringWithFormat:@"%@{}",jsonString];

}

}

}

jsonString =[NSString stringWithFormat:@"%@ }",jsonString];

return jsonString;

}


simple star program in c

for(int i=0;i<10;printf("\n",i++))

for(int j=0;j<=10+i;printf("%c",(j++ < 10-i)?' ':'*'));



// another method to get


BOOL var = TRUE;

int n = 3;

for(int i=0;iprintf("\n",i++))

{

var = TRUE;

for(int j=0;j<= n+i;j++)

{

if (j >= n-i)

{

if (var == TRUE) {

printf("*");

var = FALSE;

} else {

var = TRUE;

printf(" ");

}

} else {

printf(" ");

}

}

}



Calendar Custom Event Creation in iOS SDK

EKEventStore *eventStore = [[EKEventStore alloc] init];

EKEvent *event = [EKEvent eventWithEventStore:eventStore];

event.title = @"EVENT TITLE";

event.startDate = [[NSDate alloc] init];

event.endDate = [[NSDate alloc] initWithTimeInterval:600 sinceDate:event.startDate];

[event setCalendar:[eventStore defaultCalendarForNewEvents]];

NSError *err;

[eventStore saveEvent:event span:EKSpanThisEvent error:&err];


Note: Please include Eventkit framework and include

#import EventKit/EventKit.h

Friday, July 22, 2011

How to Find Device Width and Height in Android SDK

Display display = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int screen_width = display.getWidth();
int screen_height = display.getHeight();

Wednesday, July 20, 2011

How to Find Device Width and Height in iOS SDK

CGRect screenBounds = [[UIScreen mainScreen] bounds];
NSString *width=[NSString stringWithFormat:@"%g",screenBounds.size.width ];
NSString *height=[NSString stringWithFormat:@"%g",screenBounds.size.height ];
ight %@", width,height,NSStringFromCGRect(screenBounds));

Thursday, July 14, 2011

ASI HTTP Request + JSON Sample

  
ASIHTTPRequest *req = [ASIHTTPRequest requestWithURL:URL];
    req.delegate = self;
    req.userInfo = [NSDictionary dictionaryWithObject:@"initialRequest" forKey:@"type"];
    NSData *body = [jsonString  dataUsingEncoding:NSUTF8StringEncoding];
    [req appendPostData:body];
    [req startSynchronous];

Create a list in SwiftUI with sticky section headers

 Sample Code import SwiftUI struct ContentView : View {     @State var isCustomViewControllerDisplayed = false     @State private va...