Convert an NSURL to an NSString

前端 未结 7 866
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 04:30

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

相关标签:
7条回答
  • 2020-12-02 04:56

    In Swift :- var str_url = yourUrl.absoluteString

    It will result a url in string.

    0 讨论(0)
  • 2020-12-02 04:57

    I just fought with this very thing and this update didn't work.

    This eventually did in Swift:

    let myUrlStr : String = myUrl!.relativePath!
    
    0 讨论(0)
  • 2020-12-02 05:02

    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];
    0 讨论(0)
  • 2020-12-02 05:08

    You can use any one way

    NSString *string=[NSString stringWithFormat:@"%@",url1];
    

    or

    NSString *str=[url1 absoluteString];
    
    NSLog(@"string :: %@",string);
    

    string :: file:///var/containers/Bundle/Application/E2D7570B-D5A6-45A0-8EAAA1F7476071FE/RemoDuplicateMedia.app/loading_circle_animation.gif

    NSLog(@"str :: %@", str);
    

    str :: file:///var/containers/Bundle/Application/E2D7570B-D5A6-45A0-8EAA-A1F7476071FE/RemoDuplicateMedia.app/loading_circle_animation.gif

    0 讨论(0)
  • 2020-12-02 05:09

    In Objective-C:

    NSString *myString = myURL.absoluteString;
    

    In Swift:

    var myString = myURL.absoluteString
    

    More info in the docs:

    0 讨论(0)
  • 2020-12-02 05:15

    Try this in Swift :

    var urlString = myUrl.absoluteString
    

    Objective-C:

    NSString *urlString = [myURL absoluteString];
    
    0 讨论(0)
提交回复
热议问题