Convert an NSURL to an NSString
Convert an NSURL to an NSString
I have an app where the user can choose an image either from the built-in app images or from the iphone photo library. I use an object Occasion that has an NSString property to save the imagePath.
Now in the case of the built-in app images I do get the file name as an NSString an save in the [occasion imagePath]. But in the 2nd case where the user picks an image form the photo library I get an NSURL which I want to convert to an NSString to be able to save it in [occasion imagePath].
Is it possible to convert the NSURL to an NSString?
Answer by Randall for Convert an NSURL to an NSString
NSString *myString = [myURL absoluteString]; More info in the docs http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html
Answer by beryllium for Convert an NSURL to an NSString
Try this in Objective-C:
NSString *urlString = [myURL absoluteString]; Swift:
var urlString = myUrl.absoluteString Answer by viggio24 for Convert an NSURL to an NSString
If you're interested in the pure string:
[myUrl absoluteString]; If you're interested in the path represented by the URL (and to be used with NSFileManager methods for example):
[myUrl path]; Answer by kmiklas for Convert an NSURL to an NSString
Swift update:
var myUrlStr : String = myUrl.absoluteString Answer by Speedz for Convert an NSURL to an NSString
I just fought with this very thing and this update didn't work.
This eventually did in Swift:
let myUrlStr : String = myUrl!.relativePath! Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
0 comments:
Post a Comment