I'm trying to convert NSURL * _Nullable to non-nullable. By any chance any of you knows how can I do this?.
Here is some context:
I'm trying to use ios-oauthconsumer, and I'm trying to initialize some objects:
self.requestTokenRequest = [[OAMutableURLRequest alloc] initWithURL:_requestTokenUrl
                                                               consumer:_consumer
                                                                  token:nil
                                                                  realm:nil
                                                      signatureProvider:nil
                                                                  nonce:nil
                                                              timestamp:nil];
They are been initialize by this init:
- (id)initWithURL:(NSURL *)aUrl
         consumer:(OAConsumer *)aConsumer
            token:(OAToken *)aToken
            realm:(NSString *)aRealm
signatureProvider:(id<OASignatureProviding>)aProvider
            nonce:(NSString *)aNonce
        timestamp:(NSString *)aTimestamp {
    if ((self = [self initWithURL:aUrl consumer:aConsumer token:aToken realm:aRealm signatureProvider:aProvider])) {
      nonce = [aNonce copy];
      timestamp = [aTimestamp copy];
    }
    return self;
}
if I po I get this:

and I try to use that object. I get this warning:
I'll really appreciate if any of you knows how to convert _Nullable to non-Nullable object.
This is quite straightforward  = all you need to do is assign the _requestTokenUrl to a variable before using it in a method call. This should be enough : 
NSURL *url = _requestTokenUrl;
self.requestTokenRequest = [[OAMutableURLRequest alloc] initWithURL:url
                                                           consumer:_consumer
                                                              token:nil
                                                              realm:nil
                                                  signatureProvider:nil
                                                              nonce:nil
                                                          timestamp:nil];
Now, bear in mind that this simply silences the warning. Since your _requestTokenUrl is nullable and the method expects a nonnull object, you should check if _requestTokenUrl is actually non-nil. So the more appropriate version would look like this :
NSURL *url = _requestTokenUrl;
if (url != nil) {
    self.requestTokenRequest = [[OAMutableURLRequest alloc] initWithURL:url
                                                               consumer:_consumer
                                                                  token:nil
                                                                  realm:nil
                                                      signatureProvider:nil
                                                                  nonce:nil
                                                              timestamp:nil];
} else {
    // `_requestTokenUrl` was nil, act accordingly
}
The assignement to a variable is still required though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With