是否有另一种方法来处理 iOS Swift 2 的大量列表字典?-Xcode 卡在索引上 [英] Is there another approach to a huge list of dictionaries of lists for iOS Swift 2? -Xcode stuck at indexing

查看:27
本文介绍了是否有另一种方法来处理 iOS Swift 2 的大量列表字典?-Xcode 卡在索引上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Swift 2 语言的新手,我来自 Python.我有一个移动应用项目的结构:

I'm new to Swift 2 Language and I came from Python. I have this structure for a mobile app project:

var college = ["Bachelor of Science in Computer Science":
                ["First Year":
                  ["First Semester": [
                      "Course Code": [<values>],
                      "Course Description": [<values>],
                      "Course Units": [<values>]
                      ],  // End of First Semester
                   "Second Semester": [
                      "Course Code": [<values>],
                      "Course Description": [<values],
                      "Course Units": [<values>]
                      ]   // End of Second Semester
                  ],  // End of First Year
                 // Continue up to Fourth Year (Fifth Year if there's any)
                 // Continue to next Degree for the current college
              ]  // End of variable

显然,Xcode 似乎永远被困在索引中,并且周围的所有答案都不适合我.如果我删除这个特定变量,应用程序将加载得很好.是否有其他解决方法?

Apparently, Xcode seems to be stuck in indexing forever and none of the answers around works for me. If I remove this particular variable, the app will load just fine. Is there another workaround for this?

可能有帮助的信息:该结构在 Python 中运行良好,但当数据变大时它不适用于 Swift.当数据结构仍然很小时,列表的嵌套字典起作用.

Info that might help: The structure works fine in Python but it doesn't work with Swift when the data gets bigger. The nested dictionaries of lists works when the data structure is still small.

推荐答案

您可能会看到 Swift 很难为这种数据结构推断类型签名.指定一个可以显着改善您的编译/索引时间,例如

You might be seeing Swift struggle to infer a type signature for this data structure. Specifying one can dramatically improve your compile/index times, e.g.

var College: [String: [String: [String: [String: [type_of_values]]]]] = ["计算机科学理学士":...

编译器必须检查所有这些值,以尝试确定所有这些值共有的最具体的可用类型是什么.

As is the compiler has to inspect all of those values to try to determine what the most specific available type common to all of them is.

您可能还会发现在此处定义一组域模型很有用,这样您就不仅可以使用字符串键.这也可能会解决您的编译器性能问题.

You might also find it useful to define a set of domain models here so you're not just working with string keys. That would probably also resolve your compiler performance problem.

这篇关于是否有另一种方法来处理 iOS Swift 2 的大量列表字典?-Xcode 卡在索引上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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