What is the correct way to handle stale NSURL bookmarks?

After a lot of disappointing testing I’ve come to the following conclusions. Though logical, they’re disappointing since the resulting experience for users is far from ideal and a significant pain for developers depending on how far they’re willing to go to help users re-establish references to bookmarked resources. When I say “renew” below, I mean … Read more

Url minus query string in Objective-C

Since iOS 8/OS X 10.9, there is an easier way to do this with NSURLComponents. NSURL *url = [NSURL URLWithString:@”http://hostname.com/path?key=value”]; NSURLComponents *urlComponents = [[NSURLComponents alloc] initWithURL:url resolvingAgainstBaseURL:NO]; urlComponents.query = nil; // Strip out query parameters. NSLog(@”Result: %@”, urlComponents.string); // Should print http://hostname.com/path

Retrieve filename from NSURL

The code below should work. Updated it so I removed the top statement. I could’ve used NSString vs const char * or std::string from C++ but thought C Character Pointers would be quite appropriate for this case in point. Also revamped this so it’s in it’s own concise function: -(NSString*) extractFile:(const char*) url { NSURL … Read more

Initializer for conditional binding must have Optional type, not ‘String’

The compiler is telling you that you can’t use an if let because it’s totally unnecessary. You don’t have any optionals to unwrap: URL is not optional, and the absoluteString property isn’t optional either. if let is used exclusively to unwrap optionals. If you want to create a new constant named url, just do it: … Read more

UILabel and NSLinkAttributeName: Link is not clickable

I can answer my own question now: I am using UITextView instead of UILabel now. I have formatted the UITextView to look and behave like my labels and added: UITextView *textView = [[UITextView alloc] init]; textView.scrollEnabled = NO; textView.editable = NO; textView.textContainer.lineFragmentPadding = 0; textView.textContainerInset = UIEdgeInsetsMake(0, 0, 0, 0); textView.delegate = self; Don’t forget … Read more

Swift: save video from NSURL to user camera roll

AssetsLibrary is deprecated 1: import Photos import Photos 2: Use this code to save video from url to camera library. PHPhotoLibrary.sharedPhotoLibrary().performChanges({ PHAssetChangeRequest.creationRequestForAssetFromVideoAtFileURL(nsUrlToYourVideo) }) { saved, error in if saved { let alertController = UIAlertController(title: “Your video was successfully saved”, message: nil, preferredStyle: .Alert) let defaultAction = UIAlertAction(title: “OK”, style: .Default, handler: nil) alertController.addAction(defaultAction) self.presentViewController(alertController, animated: … Read more

NSURL with string

Your problem is the unescaped spaces in the URL. This, for instance, works: NSURL *url = [NSURL URLWithString:@”tel://1234567890×101″]; Edit: As does this.. NSURL *url2 = [NSURL URLWithString:[@”tel://1234567890 ext. 101″ stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

How to convert NSURL to String in Swift

It turns out there are properties of NSURL you can access (see Swift Reference): var directoryURL: NSURL var urlString: String = directoryURL.absoluteString // OR var urlString: String = directoryURL.relativeString // OR var urlString: String = directoryURL.relativePath // OR var urlString: String = directoryURL.path // etc.