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
I did it like this, using a variable resourceSpecifier in NSURL
SWIFT
var resourceSpecifier: String? { get }
OBJECTIVE-C
@property(readonly, copy) NSString *resourceSpecifier Discussion
This property contains the resource specifier. For example, in the URL http://www.example.com/index.html?key1=value1#jumplink, the resource specifier is //www.example.com/index.html?key1=value1#jumplink (everything after the colon).
-(NSURL*) URLByReplacingScheme
{
NSString *newUrlString = kHttpsScheme;
if([self.scheme isEqualToString:kEmbeddedScheme])
newUrlString = kHttpScheme;
newUrlString = [newUrlString stringByAppendingString:[NSString stringWithFormat:@":%@", self.resourceSpecifier]];
return [NSURL URLWithString:newUrlString];
}