我怎样才能在里面声明一个整数数组RLMObject
?
喜欢 :
dynamic var key:[Int]?
Run Code Online (Sandbox Code Playgroud)
给出以下错误:
Terminating app due to uncaught exception 'RLMException', reason: ''NSArray' is not supported as an RLMObject property. All properties must be primitives, NSString, NSDate, NSData, RLMArray, or subclasses of RLMObject. See https://realm.io/docs/objc/latest/api/Classes/RLMObject.html for more information.'
Run Code Online (Sandbox Code Playgroud) 我是初学者java并试图解决棘手的问题
输入= 777
输出应为3
7 + 7 + 7 = 21,2 + 1 = 3;
从上面的代码,如果我的输入是333我得到9作为答案,但当总和是两位数(777 = 21)时,我变得空白!
public static void main(String[] args)
{
int y=333;//if y is 777 i am getting blank
int sum=0;
String s;
char []ch;
do
{
s=String.valueOf(y);
ch=s.toCharArray();
if(ch.length>1)
{
for(int i=0;i<ch.length;i++)
{
sum+=Character.getNumericValue(ch[i]);
}
}
else
{
System.out.println(sum);
}
y=sum;
}while(ch.length>1);
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试存储字典 var items : [String:(type:String,item:AnyObject)] = [:]
例如,关键是"foo"和 items["foo"]?.type = "UILabel"
我想AnyObject
从字符串转换为给定类型.
可以这样做吗?:
//This is a string
if let myConvertedItem = items["file"]!.item as? items["file"]!.type{
//myConvertedItem is UILabel here..
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来做到这一点?
编辑:我看到了这个功能,_stdlib_getTypeName()
但是swift无法识别它.我怎么能宣布它?它还能用AnyObject
吗?
解决方案我不是在寻找:
做这样的事情:
if items["file"]!.item is UILabel{
//ok it's UILabel
}
if items["file"]!.item is SomeOtherClassName{
//ok it's some other class name
}
Run Code Online (Sandbox Code Playgroud)
因为这个if列表可能很长
谢谢!
我[].forEach
在NodeJS中遇到了奇怪的问题.
(使用NodeJs v5.4.1)
将此代码放在函数中
function _buildUserQuestionsForDisplay(question,callback){
var res = {}
["is_open","created","deleted","_id"].forEach(function(v){
res[v] = question[v]
})
...
...
}
Run Code Online (Sandbox Code Playgroud)
抛出错误:
[ "IS_OPEN", "创建", "删除", "_ ID"].的forEach(函数(V){
TypeError:无法读取未定义的属性'forEach'
如果我将代码更改为,它可以工作
var arr = ["is_open","created","deleted","_id"];
arr.forEach(function(v){
res[v] = question[v]
})
Run Code Online (Sandbox Code Playgroud)
我已经测试了相同的功能Chrome.console
并且第一种方式有效.
我知道两者都使用V8
JS引擎,这是一个bug还是Javascript规则中缺少的东西?
谢谢!