Tuesday, August 23, 2011

Android Installation

Download Andriod SDK and Eclispse


2) Launch Eclipse


3) go to help -> install new software

4) enter this url


‪http : //dl-ssl.google.com/Android/eclipse/‬

5)and configure


6) then create a new project (Others) and select google api and then launch first app



Monday, August 15, 2011

MD5 in Xcode

import --> #import CommonCrypto/CommonDigest.h
then make a Class Utility


in .h


#import Foundation/Foundation.h

#import CommonCrypto/CommonDigest.h
@interface Utilities : NSObject {

}

//generates md5 hash from a string
+ (NSString *) returnMD5Hash:(NSString*)concat;

@end
##############################################################
in .m





#import "Utilities.h"
@implementation Utilities

//generate md5 hash from string
+ (NSString *) returnMD5Hash:(NSString*)concat {
const char *concat_str = [concat UTF8String];
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5(concat_str, strlen(concat_str), result);
NSMutableString *hash = [NSMutableString string];
for (int i = 0; i < 16; i++)
[hash appendFormat:@"%02X", result[i]];
return [hash lowercaseString];

}

@end










#######################

in the main Class





NSString *myMD5String = [Utilities returnMD5Hash:@"test"];
NSLog(@" myMD5String ----------------------- %@",myMD5String);




And Its Done , Happy Coding :)




Tuesday, July 26, 2011

Uninstall Xcode

sudo /Developer/Library/uninstall-devtools –mode=all

Thursday, July 21, 2011

Core data Basics -Part 1

Welcome to the world of core data
________________________________________

step 1) import core data framework

step 2) create a coredata object -> Test.xcdatamodeld
create entity -> Class
Create Attributes-> Name , Descrioptin;

step3) in AppDelegate class add these

NSManagedObjectContext *managedObjectContext_;
NSManagedObjectModel *managedObjectModel_;
NSPersistentStoreCoordinator *persistentStoreCoordinator_;


@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;

- (NSURL *)applicationDocumentsDirectory;
- (void)saveContext;


###################################################

______________ in App delegate.m____________________________


#pragma mark -
#pragma mark Core Data stack

/**
Returns the managed object context for the application.
If the context doesn't already exist, it is created and bound to the persistent store coordinator for the application.
*/
- (NSManagedObjectContext *)managedObjectContext {

if (managedObjectContext_ != nil) {
return managedObjectContext_;
}

NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil) {
managedObjectContext_ = [[NSManagedObjectContext alloc] init];
[managedObjectContext_ setPersistentStoreCoordinator:coordinator];
}
return managedObjectContext_;
}


/**
Returns the managed object model for the application.
If the model doesn't already exist, it is created from the application's model.
*/
- (NSManagedObjectModel *)managedObjectModel {

if (managedObjectModel_ != nil) {
return managedObjectModel_;
}
NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"Test" ofType:@"momd"];
NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
managedObjectModel_ = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return managedObjectModel_;
}


/**
Returns the persistent store coordinator for the application.
If the coordinator doesn't already exist, it is created and the application's store added to it.
*/
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {

if (persistentStoreCoordinator_ != nil) {
return persistentStoreCoordinator_;
}

NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Test.sqlite"];

NSError *error = nil;
persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}

return persistentStoreCoordinator_;
}


#pragma mark -
#pragma mark Application's Documents directory

/**
Returns the URL to the application's Documents directory.
*/
- (NSURL *)applicationDocumentsDirectory {
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}







#################################

_______________ in VeiwControll.h___

step5) create text fields to enter user values
UITextField* nameTextField;
UITextField* descriptionTextField;
UITextView* ingredientsTextView;
}
@property (nonatomic,retain) IBOutlet UITextField* nameTextField;
@property (nonatomic,retain) IBOutlet UITextField* descriptionTextField;
@property (nonatomic,retain) IBOutlet UITextView* ingredientsTextView;



##################

_______________in VC.m_____________


step6) to save the data in Sqlite


- (IBAction)save:(id)sender {

CoreData_rahul_saveDataAppDelegate* delegate = [[UIApplication sharedApplication] delegate];

NSManagedObjectContext* managedObjectContext = delegate.managedObjectContext;

NSManagedObject *nam;
nam=[NSEntityDescription insertNewObjectForEntityForName:@"Class" inManagedObjectContext:managedObjectContext];

[nam setValue:nameTextField.text forKey:@"Name"];
[nam setValue:descriptionTextField.text forKey:@"Desciption"];


NSError* error;
[managedObjectContext save:&error];

[self fetchRecords]; // to show data in console
}



step 7) to display data in console we use Fetch Request


- (void)fetchRecords {

CoreData_rahul_saveDataAppDelegate* delegate = [[UIApplication sharedApplication] delegate];

NSManagedObjectContext* managedObjectContext = delegate.managedObjectContext;

NSFetchRequest *request = [[NSFetchRequest alloc] init];

[request setEntity:[NSEntityDescription entityForName:@"Class" inManagedObjectContext:managedObjectContext]];

NSError *error = nil;
NSArray *events = [managedObjectContext executeFetchRequest:request error:&error];
NSAssert2(events != nil && error == nil, @"Error fetching events: %@\n%@", [error localizedDescription], [error userInfo]);
//You were leaking your request here
[request release], request = nil;
//The following line is redundant. You are leaking an array here
//NSMutableArray *namesArray = [[NSMutableArray alloc]init];
NSArray *namesArray = [events valueForKey:@"Name"];

NSLog(@"array us %@",namesArray);


}





Thanks

Monday, July 11, 2011

retain and Copy diff

In a general setting, retaining an object will increase its retain count by one. This will help keep the object in memory and prevent it from being blown away. What this means is that if you only hold a retained version of it, you share that copy with whomever passed it to you.

Copying an object, however you do it, should create another object with duplicate values. Think of this as a clone. You do NOT share the clone with whomever passed it to you.

Wednesday, June 29, 2011

Convert Char to NsString and vice versa

char to NsString

char *a = "Testing";
NSString *aa = [NSString stringWithCString: (const char *)a encoding: NSASCIIStringEncoding];NSLog(@"%@", aa);




#############################################

NSString to c char


char * c_string = [someNSString UTF8String];

Wednesday, June 22, 2011

@selectors in obj-c

elector in Objective C
In short, Selector can either be a name of method or a message to an object when used in the source code. And SEL is the complied form of a Selector.










- (void) fooNoInputs {
NSLog(@"Does selector test");
}

- (void) fooOneInput:(NSString*) first {

// NSLog(@"Does selector test");
NSLog(@"my slectore Logs %@", first);
}

- (void)viewDidLoad
{


//
//##############################################################################

// SELCETOR test

//##############################################################################




[self performSelector:@selector(fooNoInputs)];

[self performSelector:@selector(fooOneInput:) withObject:@"firstc"];













############## difference between

[self playButtonSound]; &

[self performSelector:@selector(playButtonSound)];







Both to the same thing, but [self playButtonSound]; is definitely the normal way to invoke a method in Objective-C. However, using performSelector: allows you to call a method that is only determined at runtime.

@property in objc

Property attributes are special keywords to tell compiler how to generate the getters and setters. Here you specify two property attributes: nonatomic, which tells the compiler not to worry about multithreading, and retain, which tells the compiler to retain the passed-in variable before setting the instance variable.

In other situations, you might want to use the “assign” property attribute instead of retain, which tells the compiler NOT to retain the passed-in variable. Or perhaps the “copy” property attribute, which makes a copy of the passed-in variable before setting.

Sunday, June 19, 2011

Categories in obj-c

// Base Class
@interface ClassA : NSObject
- (NSString *) myMethod;
@end
@implementation ClassA
- (NSString*) myMethod { return @"A"; }
@end

//Category
@interface ClassA (CategoryB)
- (NSString *) myMethod;
@end
@implementation ClassA (CategoryB)
- (NSString*) myMethod { return @"B"; }
@end



Calling the method "myMethod" after including the category nets the result "B".

FEEDJIT Live