CoreData: error: (19) PRIMARY KEY must be unique

Set the Z_MAX to largest Z_PK value in the corresponding table.

UPDATE "main"."Z_PRIMARYKEY" SET "Z_MAX" = n where "Z_ENT" = n

Cited from: why is this code raising the coredata error 19 primary key must be unique

How to check the character is backspace (delete)

- (BOOL) textField:(UITextField *) textField
shouldChangeCharactersInRange:(NSRange) range
            replacementString:(NSString *) string
     if ([string length])
          if ([string characterAtIndex:0] == 10)
               NSLog(@"keyboard backspace pressed");
      return YES;

Blogged with the Flock Browser

Basic topics a mac developer should know

  • MVC Pattern
  • Memory Management
  • Archiving Data
  • User Defaults
  • Localization
  • Categories
  • Formal and informal Protocols
  • Key Value coding
  • Key Value observing
  • Custom Drawing
  • Notifications
  • Delegation
  • Blocks
  • Threads
  • Core Animation
  • Debugging
  • Instruments
  • Predicates
  • Custom Drawing
  • Bindings
Blogged with the Flock Browser

NSURLConnection Usage

– (void)sendRequestToServer:(NSURL *)url httpBody:(NSString *)methodCallString

    NSMutableURLRequest *xmlrpcRequest =[NSMutableURLRequest requestWithURL:url
    [xmlrpcRequest setHTTPMethod:@”POST”];
    [xmlrpcRequest setValue:@”text/xml” forHTTPHeaderField:@”Content-Type”];
    // set the HTTPBody with the method call string as bytes
    const char *utfString = [methodCallString UTF8String];
    NSString *utfStringLenString = [NSString stringWithFormat:@”%u”, strlen(utfString)];
    [xmlrpcRequest setHTTPBody:[NSData dataWithBytes: utfString length:strlen(utfString)]];
    // Set the Content-Length header
    [xmlrpcRequest setValue:utfStringLenString forHTTPHeaderField:@”Content-Length”];
    // create the connection with the request and start loading the data
    if (!isConnectionBusy) {
        isConnectionBusy = YES;
        NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:xmlrpcRequest delegate:self];
        if (theConnection) {
            responseData = [[NSMutableData data] retain];
        } else {
            NSLog(@”Connection Failed!”);

– (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
    if (responseData != NULL)
        [responseData setLength:0];

– (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
    [responseData appendData:data];
    //    NSString *responseString = [[[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding] autorelease];

– (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
    isConnectionBusy = NO;

    // release the connection, and the data object
    [connection release];
    // receivedData is declared as a method instance elsewhere
    [responseData release];
    // inform the user
    NSLog(@”Connection failed! Error – %@ %@”,
          [error localizedDescription],
          [[error userInfo] objectForKey:NSErrorFailingURLStringKey]);

– (void)connectionDidFinishLoading:(NSURLConnection *)connection
    isConnectionBusy = NO;
    NSString *responseString = [[NSString alloc] initWithBytes:[responseData bytes] length:[responseData length] encoding:NSUTF8StringEncoding];

    [connection release];
    connection = nil;
    [responseData release];

    [self parseData:responseString];
    [responseString release];
    // release the connection, and the data object

-(NSURLRequest *)connection:(NSURLConnection*) connection
            willSendRequest:(NSURLRequest*)    request
           redirectResponse:(NSURLResponse*) redirectResponse
    //NSLog(@”connection willSendRequest redirectResponse”);

    NSURLRequest *newRequest = request;
    if (redirectResponse)
    return newRequest;

– (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse
    return nil;

Blogged with the Flock Browser

Creating the SSL Certificate

Creating the SSL Certificate

1. Follow the steps given in the chapter 3 of Apple Push Notification Service Programming Guide to create SSL certificate.

2. Import the aps_developer_identity.cer to the keychain.Then you have to export these new cert and the private key of this cert (not the public key) and saved as .p12 files.

3. Then you use these commands to generate the cert and key in Mac’s Terminal for PEM format (Privacy Enhanced Mail Security Certificate)

  • openssl pkcs12 -clcerts -nokeys -out cert.pem -in cert.p12
  • openssl pkcs12 -nocerts -out key.pem -in key.p12    // key.p12 is the private key

4. The cert.pem and key.pem files will be used by your own program communicating with APNS.

5. Remove the passphase of private key in key.pem, do this

  • openssl rsa -in key.pem -out key.unencrypted.pem

6. Then combine the certificate and key

  • cat cert.pem key.unencrypted.pem > ck.pem

Reference :

Blogged with the Flock Browser

Escape code for % sign in NSString

The escape code for a percent sign is “%%”, so your code would look like this

[NSString stringWithFormat:@”%d%%”, someDigit];

This is also true for NSLog() and printf() formats.

Cited from

Blogged with the Flock Browser

Shortening URLs

Cited from:

NSString *url    = @””;
NSString *apiEndpoint = [NSString stringWithFormat:@””,url];
NSString *shortURL = [NSString stringWithContentsOfURL:[NSURL URLWithString:apiEndpoint]
NSLog(@”Long: %@ – Short: %@”,url,shortURL);
// Outputs Long: – Short:

Blogged with the Flock Browser