user3564078 user3564078 - 1 year ago 105
Objective-C Question

How to generate random string in Objective C based on core data values

I am developing one iPad application using storyboard and core data.For my application i need to generate one random string like 'M000142140502343524' which are not already exist in the 'data' field of the 'tableA' when click a button.

Answer Source

This will generate the random key

   NSTimeInterval  today = [[NSDate date] timeIntervalSince1970];
    NSString *intervalString = [NSString stringWithFormat:@"%f", today];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[intervalString doubleValue]];

    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyyMMddhhmm"];
    NSString *strdate=[formatter stringFromDate:date];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download