【问题标题】:How retrireve array from dictionary如何从字典中检索数组
【发布时间】:2012-03-06 06:20:28
【问题描述】:

我的 Sqlite 表中有 2 列 1.DetailsID & 2.Detailstype

我已经存储了值 id: int 和 detailstype :varchar。

在sqlite select查询中用字符串设置id为

while(sqlite3_step(selectPrefer) == SQLITE_ROW)
            {                
                NSString *detailsString = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectPrefer, 1)];
                int detailsId = (int)sqlite3_column_int(selectPrefer, 0);

                [detailsData setObject:detailsString forKey:[NSNumber numberWithInt:detailsId ]];

            }

我有一个这样的 NSmutable 字典:

(


         0 = "˚F";
        12 = Activity;
        11 = BM;
        7 = "Heart Rate";
        6 = "Nose Problem";
        2 = Rx;
        1 = BP;
        10 = Food;
        9 = "Stress Level";
        8 = Glucose;
        5 = "Pain Level";
        4 = Weight;
        3 = Events;
}
i can get arrays using allKeys & allValues but these are not in order

现在我想要单独的数组,例如

       {
             0
1
2
3
4
5
6
7
8
9
10
11
12

        )

值和键都按键的升序排列

(
            "˚F";
         Activity;
         BM;
         "Heart Rate";
         "Nose Problem";
         Rx;
         BP;
         Food;
         "Stress Level";
         Glucose;
         "Pain Level";
         Weight;
         Events;
)

在 sqlite 查询中没有任何修改 - 怎么做提前谢谢

【问题讨论】:

    标签: iphone objective-c nsmutablearray nsarray nsdictionary


    【解决方案1】:

    您应该使用dictionay 的 allKeys 和 allValues 属性:

    allKeys 返回一个包含字典键的新数组。

    allValues 返回一个包含字典值的新数组。

    试试这个:

    NSArray *keysArray = [yourDictionnay allKeys];
    NSArray *valuesArray = [yourDictionnay allvalues];
    

    希望这会有所帮助, 文森特

    【讨论】:

    【解决方案2】:

    你需要 allValues 和 allkeys。

    NSArray *values = [dictionary allValues];
    NSArray *keys  =  [dicitoary allKeys];
    

    【讨论】:

    • 我想要按 allKeys 排序的 allValues
    猜你喜欢
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-19
    • 2013-06-06
    • 1970-01-01
    • 2022-01-19
    相关资源
    最近更新 更多