Change a NSURL's scheme

前端 未结 6 2010
無奈伤痛
無奈伤痛 2021-02-02 09:34

Is there an easy way to change the scheme of a NSURL? I do realize that NSURL is immutable. My goal is to change the scheme of an URL to \"https\" if t

6条回答
  •  日久生厌
    2021-02-02 10:33

    If you are using iOS 7 and later, you can use NSURLComponents, as show here

    NSURLComponents *components = [NSURLComponents new];
    components.scheme = @"http";
    components.host = @"joris.kluivers.nl";
    components.path = @"/blog/2013/10/17/nsurlcomponents/";
    
    NSURL *url = [components URL];
    // url now equals:
    // http://joris.kluivers.nl/blog/2013/10/17/nsurlcomponents/
    

提交回复
热议问题