我想加载请求的网页并访问DOM的元素以从其中一个节点返回值.我有一些JavaScript可以做到这一点.问题是将值返回到我的应用程序的最佳方法.我看到UIWebView有一个功能
stringByEvaluatingJavaScriptFromString
和WKWebKit有功能
func evaluateJavaScript(javaScriptString:String!,completionHandler:((AnyObject!,NSError!) - > Void)!)
那么它们之间的主要区别是哪个更好,为什么我的用例呢?
//在一个片段中
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
SharedPreferences.Editor editor = preferences.edit();
editor.putString("aKeyString", "aValueString");
editor.apply()
//If I try to log the just saved value the log is empty. Though I thought the apply(); committed that value to memory instantly and later to disc. So should be readable ?
Log.d(TAG, preferences.getString("aKeyString",""));
//nothing is logged to logcat at all. Not even a blank line.
Run Code Online (Sandbox Code Playgroud)
但是,在另一个Fragment中,我需要读取该值,但返回null。
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
Log.d(TAG, "value: " + preferences.getString("aKeyString",""));
//Logs out "value: null"
Run Code Online (Sandbox Code Playgroud)
为什么它为空?我正在使用getDefaultSharedPreferences它将确保getActivity().getApplicationContext()出于相同的原因我正在访问正确的数据。
关于SO返回首选项的类似问题的帖子建议使用:
'应用();' …
Transformable使用 Core Data 搜索a 中是否存在数组元素的正确方法是什么NSPredicate?
我有一个Entity可操作Attribute的天数,其中Type的一个Transformable是给定的Custom Class [Int]。
我用它来存储整数数组。它可以存储,但当我EXC_BAD_ACCESS尝试使用 NSPredicate 获取它们时,我得到了
我知道
运营天数为 {1,2,3,4}
我正在尝试,但它们都因错误而失败。
//day is an Int (1) in this case
NSPredicate(format: "%d IN operationalDays",day)
NSPredicate(format: "%i IN operationalDays",day)
NSPredicate(format: "%@ IN operationalDays",day)
NSPredicate(format: "operationalDays CONTAINS %d",day)
NSPredicate(format: "operationalDays CONTAINS %i",day)
NSPredicate(format: "operationalDays CONTAINS %@",day)
Run Code Online (Sandbox Code Playgroud)
当我在崩溃后检查谓词时,我得到
谓词:(1 IN runningDays);
或者
谓词:(操作天数包含 1)
我有一个包含5个对象的数组.但我想迭代它,以便最终得到100个对象.一旦我到达数组索引的末尾,我可以返回并从0开始直到达到100次迭代?
假设我的数组是["a", "b", "c", "d", "e"],那么我想要的结果是:
0 = a 1 = b 2 = c 3 = d 4 = e 5 = a 6 = b 7 = c 8 = d 9 = e 10 = a
等等.
我想通过重复此列表中的项目来填充包含100个单元格的表格.