Created
January 30, 2013 16:24
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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