该filter方法是一个非常强大的工具,可以根据单个或多个条件进行过滤,但是有没有办法根据数组条件进行过滤?
类Car与属性:model,color,engineStatus.
cars 是一个几乎没有汽车的阵列一个条件看起来像:
let currModel = `Opel`
let filterdObject = cars.filter { $0.model == currModel }
Run Code Online (Sandbox Code Playgroud)
两个或多个条件看起来像:
let currModel = `Opel`
let currColor = `Green`
let filterdObject = cars.filter { $0.model == currModel || $0.color == currColor }
Run Code Online (Sandbox Code Playgroud)
我的问题是我怎么能用数组过滤:
阵列具有例如两种颜色blue和green.我想cars用这些颜色过滤.我的意思是得到一个公式n-conditions.
首先,我创建了一个应用程序,然后开始对其进行测试(知道这不是一种好方法),在进行解析等工作时一切正常,但是经过几次测试后却出现了错误:
Newtonsoft.Json.JsonReaderException:从JsonReader读取JObject时出错。当前JsonReader项不是对象:StartArray。路径'',第1行,位置1。
错误发生时有jObject = JObject.Parse(content);有arrayList = JArray.Parse(content);
internal JObject DoParse(string content)
{
JObject jObject = new JObject();
if (content != null)
{
if (content.Contains("Unable"))
{
MessageBox.Show("Not found.", "Error");
}
else
{
jObject = JObject.Parse(content);
}
}
return jObject;
}
internal JArray DoParseOnList(string content)
{
JArray arrayList = new JArray();
if (content != null)
{
if (content.Contains("Unable"))
{
MessageBox.Show("Not found.", "Error");
}
else
{
arrayList = JArray.Parse(content);
}
}
else { }
return arrayList;
}
Run Code Online (Sandbox Code Playgroud)
任何想法有什么问题吗?顺便说一句。string content …
我无法找到任何这将是有益的(可能becouse我没有经历过Web开发人员)如何设置Vuetify与Symfony项目。我缺少一个css-loader并且无法弄清楚它应该如何设置。
// webpack.config.js
var Encore = require('@symfony/webpack-encore');
const { VueLoaderPlugin } = require('vue-loader');
Encore
// the project directory where all compiled assets will be stored
.setOutputPath('public/build/')
// the public path used by the web server to access the previous directory
.setPublicPath('/build')
// will create public/build/app.js and public/build/app.css
.addEntry('app', './assets/js/app.js')
// allow legacy applications to use $/jQuery as a global variable
.autoProvidejQuery()
// enable source maps during development
.enableSourceMaps(!Encore.isProduction())
// empty the outputPath dir before …Run Code Online (Sandbox Code Playgroud) 我怎样才能从目录中的每个文件中获取日期?
let directoryContent = try fileManager.contentsOfDirectory(atPath: directoryURL.path)
Run Code Online (Sandbox Code Playgroud)
这就是我从目录中获取文件的方式.我发现了一些方法:
directoryContent.Contains(...)
数据较旧的文件几天 - 我怎么检查它?
然后;
let fileAttributes = try fileManager.attributesOfItem(atPath: directoryURL.path)
Run Code Online (Sandbox Code Playgroud)
它将在目录中给我最后一个文件.
这将以字节为单位返回日期:
for var i in 0..<directoryContent.count {
let date = directoryContent.index(after: i).description.data(using: String.Encoding.utf8)!
print(date)
}
Run Code Online (Sandbox Code Playgroud)
哪一个是从所有文件中恢复日期的最佳方法,或检查目录是否对比X时间早的特定日期.
提前致谢!
使用参数在GET中以哪种方式重新定义GET?
示例:
https://my-side.com/data?token=AS7F87SAD84889AD/
Run Code Online (Sandbox Code Playgroud)
提前致谢 !
我一直在寻找从结构创建字典的最有效方法。经过细致的研究,我发现了一种通过初始化所有属性来转换它的简便方法:
func toDictionary() -> [String : AnyObject] {
let dictionary: [String: AnyObject] = ["firstProperty" : sth, "secondProperty" : "sth2"]
return dictionary
}
Run Code Online (Sandbox Code Playgroud)
但是,等等。我是否必须在结构中每次都初始化它?他们可能有很多财产。.这让我思考。如果我可以通过类的循环获得属性怎么办。是的,可以使用Mirror反射。经过一段时间的尝试,我明白了—而不是上面的功能,我编写了实现一个功能的协议。
protocol Mirrorable {
func toDictionary() -> [String : AnyObject]
}
Run Code Online (Sandbox Code Playgroud)
然后在我的结构中,我可以简单地使用:
extension MyStructure/MyClass : Mirrorable {
func toDictionary() -> [String : AnyObject] {
let reflection = Mirror(reflecting: self).children
var dictionary = [String : AnyObject]()
for (label, value) in reflection {
dictionary[label!] = value as AnyObject
}
return dictionary
}
}
Run Code Online (Sandbox Code Playgroud)
好奇心并没有让我停止思考。哪种方法更有效?
我在更改应用程序中的根目录时遇到问题。
我的应用程序的设计。登录应用程序后,我想将 root vc 更改为UITabBarViewController清理堆栈。
我遇到过很多问题。
将 vc 设置为应用登录操作上的选项卡栏 -> 或在底部 vc 中:
self.performSegue(withIdentifier: "goToMainTabBar", sender: nil)
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let vc = segue.destination as? TabBarViewController {
UIApplication.shared.keyWindow?.rootViewController = vc
}
}
Run Code Online (Sandbox Code Playgroud)该应用程序将崩溃:
Application tried to present modal view controller on itself. Presenting controller is TabBarViewController
Run Code Online (Sandbox Code Playgroud)
下一个问题是我们是否在TabBarViewController viewDidLoaded.
UIApplication.shared.keyWindow?.rootViewController = self
嵌入的选项卡栏项目UINavigationController本身没有导航控制器,因此导航 vc 未实例化?因为当我进入项目 vc child -> 我不能再回来了。如果我不改变 root vc 一切都很好。
我知道有很多与此主题相关的线程,但是我认为这有点不同,因为我不是从数据库中保存或获取对象,而且它们始终在主线程中。
我的问题很棘手,我可以在同一类中修改领域对象,但是当我将它作为参数传递给另一个时,就会出现类似的情况。我试图了解为什么会这样?它不应该发生。
'RLMException', reason: 'Attempting to modify object outside of a write transaction - call beginWriteTransaction on an RLMRealm instance first.'
Run Code Online (Sandbox Code Playgroud)
这是我的数据库结构:
持久性是一种协议,数据库中的每个对象都共享该协议。
public protocol Persistable {
associatedtype PropertyValue: PropertyValueType
associatedtype ManagedObject: RealmSwift.Object
associatedtype Query: QueryType
init(managedObject: ManagedObject)
func getManagedObject() -> ManagedObject
}
public typealias PropertyValuePair = (name: String, value: Any)
public protocol PropertyValueType {
var propertyValuePair: PropertyValuePair { get }
}
public protocol QueryType {
var predicate: NSPredicate? { get }
var sortDescriptors: [SortDescriptor] { get }
} …Run Code Online (Sandbox Code Playgroud)swift ×6
swift3 ×2
c# ×1
date ×1
dictionary ×1
ios ×1
json ×1
json.net ×1
nsurlsession ×1
parsing ×1
realm ×1
reflection ×1
symfony ×1
unit-testing ×1
vue.js ×1
vuetify.js ×1
webpack ×1