我有一个 Realm 闭包,用于更新已更改的行:
try realm.write {
realm.create(Product.self, value: ["itemgroup": item.itemgroup,
"itembrand": item.itembrand,
"itemtype": item.itemtype,
"itemsubtype": item.itemsubtype,
"basedescription": item.basedescription,
"info": item.info,
"upc": item.upc,
"upc2": item.upc2,
"upc3": item.upc3,
"upc4": item.upc4,
"upc5": item.upc5,
"baseprice": item.baseprice,
"proprice": item.proprice,
"retailprice": item.retailprice,
"stdprice": item.stdprice,
"caseqty": item.caseqty,
"spord": item.spord,
"category": item.category,
"categorycode": item.categorycode,
"allowinbc": item.allowinbc,
"allowinab": item.allowinab], update: true)
}
但是,编译需要将近 10 分钟!
这是我的模型类:
class Product: Object {
dynamic var itemno: String = ""
dynamic var itemgroup: String = ""
dynamic var itembrand: String = ""
dynamic var itemtype: String = ""
dynamic var itemsubtype: String = ""
dynamic var basedescription: String = ""
dynamic var info: String = ""
dynamic var upc: String = ""
dynamic var upc2: String = ""
dynamic var upc3: String = ""
dynamic var upc4: String = ""
dynamic var upc5: String = ""
dynamic var baseprice: Double = 0.00
dynamic var proprice: Double = 0.00
dynamic var retailprice: Double = 0.00
dynamic var stdprice: Double = 0.00
dynamic var caseqty: Int = 0
dynamic var spord: String = ""
dynamic var category: String = ""
dynamic var categorycode: String = ""
dynamic var allowinbc: String = ""
dynamic var allowinab: String = ""
override class func primaryKey() -> String {
return "itemno"
}
convenience init(itemno: String, itemgroup: String, itembrand: String, itemtype: String, itemsubtype: String, basedescription: String, info: String, upc: String, upc2: String, upc3: String, upc4: String, upc5: String, baseprice: Double, proprice: Double, retailprice: Double, stdprice: Double, caseqty: Int, spord: String, category: String, categorycode: String, allowinbc: String, allowinab: String) {
self.init()
self.itemno = itemno
self.itemgroup = itemgroup
self.itembrand = itembrand
self.itemtype = itemtype
self.itemsubtype = itemsubtype
self.basedescription = basedescription
self.info = info
self.upc = upc
self.upc2 = upc2
self.upc3 = upc3
self.upc4 = upc4
self.upc5 = upc5
self.baseprice = baseprice
self.proprice = proprice
self.retailprice = retailprice
self.stdprice = stdprice
self.caseqty = caseqty
self.spord = spord
self.category = category
self.categorycode = categorycode
self.allowinbc = allowinbc
self.allowinab = allowinab
}
}
我可以对我的代码做些什么来加快编译速度?
谢谢。
最佳答案
这里没有真正的“最佳”答案,因为所有答案都非常有帮助。编译大型 Swift 字典的最快方法是不让编译器推断任何东西 的类型。这意味着您需要定义字典中每个项目的数据类型(包括字典本身)。
我的字典编译最快的方法是:
try realm.write {
let dict: [String: Any] = ["itemgroup": item.itemgroup as String,
"itembrand": item.itembrand as String,
"itemtype": item.itemtype as String,
"itemsubtype": item.itemsubtype as String,
"basedescription": item.basedescription as String,
"info": item.info as String,
"upc": item.upc as String,
"upc2": item.upc2 as String,
"upc3": item.upc3 as String,
"upc4": item.upc4 as String,
"upc5": item.upc5 as String,
"baseprice": item.baseprice as Double,
"proprice": item.proprice as Double,
"retailprice": item.retailprice as Double,
"stdprice": item.stdprice as Double,
"caseqty": item.caseqty as Int,
"spord": item.spord as String,
"category": item.category as String,
"categorycode": item.categorycode,
"allowinbc": item.allowinbc as String,
"allowinab": item.allowinab as String]
realm.create(Product.self, value: dict, update: true)
}
关于Swift 字典需要很长时间才能编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42702559/
当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/
我注意到像bundler这样的项目在每个specfile中执行requirespec_helper我还注意到rspec使用选项--require,它允许您在引导rspec时要求一个文件。您还可以将其添加到.rspec文件中,因此只要您运行不带参数的rspec就会添加它。使用上述方法有什么缺点可以解释为什么像bundler这样的项目选择在每个规范文件中都需要spec_helper吗? 最佳答案 我不在Bundler上工作,所以我不能直接谈论他们的做法。并非所有项目都checkin.rspec文件。原因是这个文件,通常按照当前的惯例,只
我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121
我不知道为什么,但是当我设置这个设置时它无法编译设置:static_cache_control,[:public,:max_age=>300]这是我得到的syntaxerror,unexpectedtASSOC,expecting']'(SyntaxError)set:static_cache_control,[:public,:max_age=>300]^我只想将“过期”header设置为css、javaascript和图像文件。谢谢。 最佳答案 我猜您使用的是Ruby1.8.7。Sinatra文档中显示的语法似乎是在Ruby1.
这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Rubysyntaxquestion:Rational(a,b)andRational.new!(a,b)我正在阅读ruby镐书,我对创建有理数的语法感到困惑。Rational(3,4)*Rational(1,2)产生=>3/8为什么Rational不需要new方法(我还注意到例如我可以在没有new方法的情况下创建字符串)?
前言一般来说,前端根据后台返回code码展示对应内容只需要在前台判断code值展示对应的内容即可,但要是匹配的code码比较多或者多个页面用到时,为了便于后期维护,后台就会使用字典表让前端匹配,下面我将在微信小程序中通过wxs的方法实现这个操作。为什么要使用wxs?{{method(a,b)}}可以看到,上述代码是一个调用方法传值的操作,在vue中很常见,多用于数据之间的转换,但由于微信小程序诸多限制的原因,你并不能优雅的这样操作,可能有人会说,为什么不用if判断实现呢?但是if判断的局限性在于如果存在数据量过大时,大量重复性操作和if判断会让你的代码显得异常冗余。wxswxs相当于是一个独立
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
-if!request.path_info.include?'A'%{:id=>'A'}"Text"-else"Text"“文本”写了两次。我怎样才能只写一次并同时检查path_info是否包含“A”? 最佳答案 有两种方法可以做到这一点。使用部分,或使用content_forblock:如果“文本”较长,或者是一个重要的子树,您可以将其提取到一个部分。这会使您的代码变干一点。在给出的示例中,这似乎有点矫枉过正。在这种情况下更好的方法是使用content_forblock,如下所示:-if!request.path_info.inc
我需要用任何语言编写一个算法,根据3个因素对数组进行排序。我以度假村为例(如Hipmunk)。假设我想去度假。我想要最便宜的地方、最好的评论和最多的景点。但是,显然我找不到在所有3个中都排名第一的方法。Example(assumingthereare20importantattractions):ResortA:$150/night...98/100infavorablereviews...18of20attractionsResortB:$99/night...85/100infavorablereviews...12of20attractionsResortC:$120/night
修改(澄清问题)我已经花了几天时间试图弄清楚如何从Facebook游戏中抓取特定信息;但是,我遇到了一堵又一堵砖墙。据我所知,主要问题如下。我可以使用Chrome的检查元素工具手动查找我需要的html-它似乎位于iframe中。但是,当我尝试抓取该iframe时,它是空的(属性除外):如果我使用浏览器的“查看页面源代码”工具,这与我看到的输出相同。我不明白为什么我看不到iframe中的数据。答案不是它是由AJAX之后添加的。(我知道这既是因为“查看页面源代码”可以读取Ajax添加的数据,也是因为我有b/c我一直等到我可以看到数据页面之后才抓取它,但它仍然不存在)。发生这种情况是因为