Skip to content

Instantly share code, notes, and snippets.

@b-adams
Created January 30, 2013 16:24
Show Gist options
  • Save b-adams/4674408 to your computer and use it in GitHub Desktop.
Save b-adams/4674408 to your computer and use it in GitHub Desktop.
Crude way to tack http:// on to front of a text field, if it's not already present
#import "DEAppDelegate.h"
@implementation DEAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
}
- (IBAction)processURL:(id)sender {
NSString* theURLString = nil;
theURLString = [[self theURLbar] stringValue];
NSLog(@"Retrieved string [%@] from GUI", theURLString);
/* This approach didn't work
NSURL* theRealURL = nil;
theRealURL = [NSURL URLWithString:theURLString];
NSLog(@"Converted to URL [%@]", theRealURL);
theURLString = [theRealURL absoluteString];
NSLog(@"Sending string [%@] to GUI", theURLString);
[[self theURLbar] setStringValue:theURLString];
*/
if(! [[theURLString substringToIndex:7] isEqualToString:@"http://"])
{
//Log line because I was getting the index wrong so it always failed
NSLog(@"Substring was... [%@]", [theURLString substringToIndex:6]);
theURLString = [NSString stringWithFormat:@"http://%@", theURLString];
}
NSLog(@"Sending string [%@] to GUI", theURLString);
[[self theURLbar] setStringValue:theURLString];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment