__NSCFConstantString && __NSPlaceholderDictionary
一
-[__NSCFConstantString size]: unrecognized selector sent to instance 0x53ea70
该错误是在我将NSString类型的参数赋值给UIImage类型的时候报出的,查了一会才查出是这的问题。
如果大家不是这个问题查一下是不是也是赋值类型错了。
二
[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from object
Objective-C中,NSDictionary初始化的方法有很多种
方法1: [NSDictionary dictionaryWithObjectsAndKeys:<#(id), ...#>, nil]
方法2: NSDictionary *dic = @{@"key":value}
方法2,如果你的value是为nil 必将引发崩溃:
'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]
意思就是说使用[__NSPlaceholderDictionary initWithObjects:forKeys:count:]这个初始化方法,发现keys count和objcects的个数不匹配了
如何规避?
在使用@{@”key”:value} 这种方式初始化的时候,一定要对value做是否为nil的判断,为nil就不要加入Dictionary
#define UNNULL_STRING(string) (string && ![string isKindOfClass:[NSNull class]]) ? string : @""//非空字符串 self.string = NONULL_STRING(string);
或
使用标准的初始化方法:
NSDictionary dictionaryWithObjectsAndKeys:value1,@"v1",value2,@"v2",value3,@"v3", nil];
或其它的几个初始化方法进行初始化,这样如果value为nil就不会加入字典,使用 objectForKey:取出来的对象就会为nil对象,不会引发崩溃。
关联:
使用@[]方法初始化NSArray也有此坑,规避方法同字典一样
参考:
https://blog.csdn.net/yuanpeng1014/article/details/62215115
__NSCFConstantString && __NSPlaceholderDictionary的更多相关文章
- __NSCFConstantString
-[__NSCFConstantString size]: unrecognized selector sent to instance 0x53ea70 该错误是在我将NSString类型的参数赋值 ...
- Xcode编译错误__NSCFConstantString
__NSCFConstantString:主要错误就是数据类型造成的,然后就是检查哪个地方造成的数据类型调用错误 错误一:'-[__NSCFConstantString _imageThatSuppr ...
- Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
报错: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlace ...
- * -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]’
错误描述: * -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object fr ...
- 解决从服务器获取的数组是 __NSCFConstantString以及""没有空格字符串的问题
AJ分享,必须精品 问题 项目遇到了个bug,从服务器获取到的数据是这样的 { status = 1, data = [ { uid = 161, type = 2, id = 79, addtime ...
- [__NSCFConstantString size]: unrecognized selector sent to instance 错误
因为使用时候的类型和初始化的对象类型不匹配造成的,例如 - (NSMutableDictionary *)getMenuItems{ NSArray *defaultTmp = [NSArray ...
- iOS项目运行出现:[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object
说白了就是 字典初始化 的时候 放入空的值了 下面这个比较具体 错误原因: NSDictionary *dic = @{@"key":value}这个初始化方法,发现keys co ...
- iOS 创建模型时自动生成属性
转载 mark666(简书作者), 链接:http://www.jianshu.com/p/63ee533a7705 我们在创建模型的时候,常常要写一大堆恶心的@property(nonatomic, ...
- 1.2.1 OC概述
本文并非最终版本,如想关注更新或更正的内容,详见文末的联系方式,如有疏忽和遗漏,欢迎指正. 本文相关目录:(链接为简书链接) ====================== 所属文集:1.2 Objec ...
随机推荐
- Pragma: no-cache
PHP Advanced and Object-Oriented Programming Larry Ullman Last-Modified 最后修改时间 Expires 过期时间 Pragma ...
- IE8 select 动态下拉遇到的问题
发生背景:经QC测试程序一直没问题,到客户测试竟然出现了下拉窗口失效. 检查发现客户用的IE ,360 浏览器都出现一样的问题,据说360是引用IE的核心. 看下IE版本是 8的..... 开发和Q ...
- 前端 HTML 简介
HTML HTML是一个网页的主体部分,也是一个网页的基础.因为一个网页可以没有样式,可以没有交互,但是必须要有网页需要呈现的内容.所以HTML部分是整个前端的基础. HTML,全称是超文本标记语言( ...
- MyEclipse安装及破解步骤
MyEclipse2013 (32+64)下载地址(建议使用迅雷下载)http://downloads.myeclipseide.com/downloads/products/eworkbench/2 ...
- linux报错 find: missing argument to `-exec'
在linux下使用find命令时,报错:find: missing argument to `-exec' 具体执行命令为: find /u03 -name server.xml -exec grep ...
- npm设置淘宝镜像
npm config set registry https://registry.npm.taobao.org --global npm config set disturl https://npm. ...
- vue中两种路由跳转拼接参数
this.$router.push({name:"Home",query:{id:1,name:2}}) // 取到路由带过来的参数 let routerParams = this ...
- Oil Deposits(poj 1526 DFS入门题)
http://poj.org/problem?id=1562 ...
- dp训练
根据这位大佬的https://www.cnblogs.com/Bunnycxk/p/7360183.html 题目链接:https://www.luogu.org/problemnew/show/P3 ...
- [LeetCode] 557. Reverse Words in a String III_Easy tag: String
Given a string, you need to reverse the order of characters in each word within a sentence while sti ...