Ios 在cocoapods中加载资源包错误
我试着做我自己的椰子荚,我用图像。 当我遵循教程时,我会遇到一个错误 .podspecIos 在cocoapods中加载资源包错误,ios,objective-c,cocoapods,nsbundle,Ios,Objective C,Cocoapods,Nsbundle,我试着做我自己的椰子荚,我用图像。 当我遵循教程时,我会遇到一个错误 .podspec s.resource_bundles = { 'SSSlidingSelector' => ['SSSlidingSelector/Assets/*.xcassets'] } Class/slidengselector.m -(UIImage*)getImageWithName:(NSString*)imageName{ NSBundle*bundle=[NSBundle bundle
s.resource_bundles = {
'SSSlidingSelector' => ['SSSlidingSelector/Assets/*.xcassets']
}
Class/slidengselector.m
-(UIImage*)getImageWithName:(NSString*)imageName{
NSBundle*bundle=[NSBundle bundleForClass:[self class]];
NSURL*url=[bundle URLForResource:@“SSSlidingSelector”及其扩展名:@“bundle”];
NSBundle*targetBundle=[NSBundle bundlewithur:url];
UIImage*image=[UIImage imageName:imageName
内置:targetBundle
与traitcollection兼容:nil];
返回图像;
}
错误
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSBundle initWithURL:]: nil URL argument'
屏幕截图
我的代码有什么问题?
thks您的代码没有问题 版本1.0.1上的Cocoapods支持资产目录。请检查您的电脑是否在终端中运行
pod--version
如果一个新的pod安装没有解决,那么资产目录上的xCode新构建系统(如上所述)就可能是您的问题
您可以在文件
工作区设置…
生成系统
上更改生成系统。尝试将其设置为旧版生成系统
我刚刚测试了此功能,功能正常运行。您正在使用哪一版本的Cocoapods?1.7.5@alxlives
- (UIImage *)getImageWithName:(NSString *)imageName {
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
UIImage *image = [UIImage imageNamed:imageName
inBundle:bundle
compatibleWithTraitCollection:nil];
return image;
}