小编Dan*_*rom的帖子

在Realm Swift中声明一个Int数组

我怎样才能在里面声明一个整数数组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)

arrays realm ios swift

18
推荐指数
3
解决办法
1万
查看次数

到总和的数字之和是一位数

我是初学者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)

java do-while

7
推荐指数
1
解决办法
2521
查看次数

Swift,如果允许的话,按给定的字符串强制转换为?someString

我正在尝试存储字典 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列表可能很长

谢谢!

casting dynamic ios swift

6
推荐指数
2
解决办法
5129
查看次数

NodeJS [] .forEach undefined

[].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并且第一种方式有效.
我知道两者都使用V8JS引擎,这是一个bug还是Javascript规则中缺少的东西?

谢谢!

javascript v8 node.js

5
推荐指数
1
解决办法
1016
查看次数

标签 统计

ios ×2

swift ×2

arrays ×1

casting ×1

do-while ×1

dynamic ×1

java ×1

javascript ×1

node.js ×1

realm ×1

v8 ×1