Strange Issue with NSURL with Xocode6.1

好久不见. 提交于 2019-12-13 23:12:04

问题


I have a strange issue with Xcode6.1

_mainURl is my ' ServerLink '

service is ' GetUserById '

NSString* str = [NSString stringWithFormat:@"%@%@",_mainURl,service];
NSURL *url = [NSURL URLWithString:str];

When I append two strings and Create a url with NSURL, url getting 'null'

But, When I directly given the server link followed by serviceName I can generate URL.

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"ServerLink/GetUserById"]];

回答1:


Based on what you have written, the string you format would be "ServerLinkGetUserById". That is different to the string you enter manually of @"ServerLink/GetUserById".

Try updating your format to be:

NSString* str = [NSString stringWithFormat:@"%@/%@",_mainURl,service];



回答2:


NSString* str = [NSString stringWithFormat:@"%@/%@",_mainURl,service];
NSURL *url = [NSURL URLWithString:str];

don't you try like this ??

i think i am not sure exact what issue having you but as your bellow description, i think you left this part



来源:https://stackoverflow.com/questions/28170656/strange-issue-with-nsurl-with-xocode6-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!