objective-cnsstringfoundation

NSString to NSURL?


Trying to convert a string to NSURL and this is not happening.

barcodeTextLabel.text = foundCode.barcodeString;
urlToGrab = [NSString stringWithFormat:@"%@", foundCode.barcodeString]; // foundCode.barcodeString is an NSString

urlToGrab shows the following "error invalid CFStringRef"


Solution

  • This is how you create an NSURL from an NSString:

    NSURL *url = [NSURL URLWithString:@"https://www.google.com"];