iOS Swift 多维数组 - 编译需要很长时间.我应该改变什么? [英] iOS Swift Multiple dimension arrays - compiliing takes ages. What should I change?

查看:19
本文介绍了iOS Swift 多维数组 - 编译需要很长时间.我应该改变什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 swift 的新手.以前从未在 ObjC 中编程.我的 iOS 应用程序有问题,通过选择器查询数组非常简单.

I am new at swift. Never programming in ObjC before. I have got a problem with iOS application, very simple-querying arrays via the picker.

我有 4 个这样的多维数组:

I've got 4 multidimensional arrays like this one:

let Setting = [
    [0,0,0,0,0,0,2230],
    [0,0,0,0,0,2230,2157],
    [0,0,0,0,2230,2230,2085],
    [0,0,0,0,2230,2226,2017],
    [0,0,0,2230,2230,2222,1949],
    [0,0,2230,2230,2230,2218,1880],
    [0,0,2230,2230,2230,2135,1807],
    [0,2230,2230,2230,2230,2052,1735],
    [0,2230,2230,2230,2163,1965,1655],
    [2230,2230,2230,2230,2096,1878,1576],
    [2230,2230,2230,2191,2022,1793,1497],
    [2230,2230,2230,2096,1909,1708,1415],
    [2230,2230,2171,2003,1818,1623,1337],
    [2230,2230,2112,1910,1728,1539,1259],
    [2197,2214,2021,1820,1639,1454,1195],
    [2164,2199,1930,1731,1551,1370,1131],
    [2066,2104,1842,1645,1465,1302,1067],
    [1969,2010,1755,1559,1380,1234,1003],
    [1884,1902,1650,1460,1294,1155,0],
    [1799,1794,1546,1362,1209,1077,0],
    [1726,1665,1429,1259,1110,0,0],
    [1654,1537,1312,1157,1012,0,0],
    [1579,1422,1211,1059,0,0,0],
    [1505,1308,1111,961,0,0,0]
]

如果我删除这些数组(或使用较小的,例如 2 x 2),应用程序中的一切都可以完美运行.当我把它全部放在合适的地方它将一直执行索引".以 100% 的速度运行我的 CPU

Everything works perfectly in the aplication if I remove these arrays (or use smaller e.g. 2 by 2). When I put it all at the proper place it will perform "indexing" all the time. Running my CPU at 100%

当我尝试运行时 - 即使 10 小时后它也不会编译.只是停留在编译 swift 源文件.

When I try to run - it never compils, even after 10 hours. Just stuck at "Compiling swift source files.

我搜索了不同的数据存储,但我需要这些数字的确切位置.数字之间只有很小的相关性,因此它们不能变成等式.

I searched for different data storage but I need these numbers in exact places. There is only small corelation between numbers so they cannot be changed into equation.

我可以做什么来编译这个应用程序?

What I can do to compile this aplication?

推荐答案

Swift 很难推导出数组类型.你只需要告诉 Swift 它是一个 Int 数组:

Swift it is having a hard time trying to deduct the array type. You just have to tell Swift it is an Array of Array of Ints:

let setting:[[Int]] = [
    [0,0,0,0,0,0,2230],
    [0,0,0,0,0,2230,2157],
    [0,0,0,0,2230,2230,2085],
    [0,0,0,0,2230,2226,2017],
    [0,0,0,2230,2230,2222,1949],
    [0,0,2230,2230,2230,2218,1880],
    [0,0,2230,2230,2230,2135,1807],
    [0,2230,2230,2230,2230,2052,1735],
    [0,2230,2230,2230,2163,1965,1655],
    [2230,2230,2230,2230,2096,1878,1576],
    [2230,2230,2230,2191,2022,1793,1497],
    [2230,2230,2230,2096,1909,1708,1415],
    [2230,2230,2171,2003,1818,1623,1337],
    [2230,2230,2112,1910,1728,1539,1259],
    [2197,2214,2021,1820,1639,1454,1195],
    [2164,2199,1930,1731,1551,1370,1131],
    [2066,2104,1842,1645,1465,1302,1067],
    [1969,2010,1755,1559,1380,1234,1003],
    [1884,1902,1650,1460,1294,1155,0],
    [1799,1794,1546,1362,1209,1077,0],
    [1726,1665,1429,1259,1110,0,0],
    [1654,1537,1312,1157,1012,0,0],
    [1579,1422,1211,1059,0,0,0],
    [1505,1308,1111,961,0,0,0]
]

注意:根据 Swift 约定,您应该以小写字母开头命名您的变量.

Note: By Swift convention you should name your vars starting with a lowercase letter.

这篇关于iOS Swift 多维数组 - 编译需要很长时间.我应该改变什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆