Tag Archives: NSData*

NSURL Tips

# Loading a string from a website
(this will block until it loads)

    NSURL *url;
    NSData *data;
    NSString *blork;
    url = [NSURL URLWithString: @"https://langui.net/"];
    data = [url resourceDataUsingCache: NO];
    blork = [[NSString alloc] initWithData: data  encoding: NSASCIIStringEncoding];

# Loading an image from a website
(this will block until it loads)

    NSURL *url;
    NSData *data;
    NSImage *blork;
    url = [NSURL URLWithString: @"https://langui.net/wp-content/uploads/2011/03/banner.png"];
    data = [url resourceDataUsingCache: NO];
    blork = [[NSImage alloc] initWithData: data];

# Open an URL in iphone safari

    NSURL *url = [NSURL URLWithString: @"https://langui.net/"];
    [[UIApplication sharedApplication] openURL: url];

More tips available here: http://borkware.com/quickies/

Converting NSString* to NSData* and Vice Versa

NSString* str = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSData* data = [str dataUsingEncoding: NSASCIIStringEncoding];