[英]NSInvalidArgumentException with stringByAppendingPathComponent
i have a bundel settings with a string : version 我有一个带有字符串的Bundel设置:版本
in my bundle settings version = 2.9.1 在我的捆绑软件设置版本中= 2.9.1
in my project, if i use this code, all is good : 在我的项目中,如果我使用此代码,一切都很好:
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"ma/V_2.9.1/gma2/fixture_layers/ifocus.xml"];
if i use this code : 如果我使用此代码:
NSString *path = [documentsDirectory stringByAppendingPathComponent:(@"ma/V_%@/gma2/fixture_layers/ifocus.xml", version)];
i have this error : 我有这个错误:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITextField length]: unrecognized selector sent to instance 0x9753190' *由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“-[UITextField长度]:无法识别的选择器已发送到实例0x9753190”
NSString * path = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@“ ma/V_%@/gma2/fixture_layers/ifocus.xml”,版本]];
Since you're already including multiple /'s in your string, there's no advantage to using stringByAppendingPathComponent. 由于您已经在字符串中包含多个/,因此使用stringByAppendingPathComponent没有优势。 So you may as well just use: 因此,您最好只使用:
NSString* path = [documentsDirectory stringByAppendingFormat:@"ma/V_%@/gma2/fixture_layers/ifocus.xml", version];
Another option, that gives you the benefit of stringByAppendingPathComponent, is to break it right down like this: 给您带来stringByAppendingPathComponent好处的另一种选择是像这样将其分解:
NSString* path = [[[[[documentsDirectory stringByAppendingPathComponent:@"ma"] stringByAppendingPathComponent:[NSString stringWithFormat:@"V_%@", version]] stringByAppendingPathComponent:@"gma2"] stringByAppendingPathComponent:@"fixture_layers"] stringByAppendingPathComponent:@"ifocus.xml"];
But that's kind of ugly. 但这有点丑陋。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.