Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是iOS开发的新手。有时我的 API 服务器会返回一个nil值。当我尝试创建NSURL实例时,这会引发错误。
nil
NSURL
这是条件:
NSString *tmpURL = nil; NSURL *url = [NSURL URLFromString:tmpURL];
在这种情况下,它会使应用程序崩溃。我只想使url变量为零,而不是引发错误。
url
怎么样:
NSString *tmpURL = nil; NSURL *url = tmpUrl ? [NSURL URLFromString:tmpURL] : nil;