如何过滤swift 4的对象数组,然后删除(How to filter array of objects swift 4 then remove after)

我想避免出现此错误图像的错误

这是INDEX超出范围。 我试图通过一个数组循环,但是当我找到我想要删除的东西时,我将它删除,但数组的.count与for循环的迭代保持不变,我该如何解决这个问题?

这是运行时的控制台

test i:0  count: 3
test i:1  count: 3
test i:2  count: 2

然而,to:in

    for i in stride(from: 0, to: count, by: 1)

仍然似乎是3 ...

有人可以告诉我如何过滤这个数组或循环并移除? 只要它工作,我不在乎它是什么


I want to avoid getting this error image of error

which is INDEX out of range. Im trying to loop through an array but when I find something I want to remove , I delete it yet the .count of the array remains the same for that iteration of the for loop , how can I fix this?

here is console when run

test i:0  count: 3
test i:1  count: 3
test i:2  count: 2

yet the to: in

    for i in stride(from: 0, to: count, by: 1)

still seems to be 3...

Can Someone show me how to filter this array or loop through and remove? as long as it works i dont care what it is


原文:https://stackoverflow.com/questions/50119824
2021-12-14 09:12

满意答案

无法更新EntitySet,因为它具有DefiningQuery,并且元素中不存在元素以支持当前操作。

确保你的表有一个主键

如果不添加主键并更新实体框架模型并再次运行。

资源:


Unable to update the EntitySet because it has a DefiningQuery and no element exists in the element to support the current operation.

Make sure that your table has a primary key !

If not add the primary key and update the Entity Framework model and run again.

Source:

相关问答

更多

db.SaveChanges()爆炸与事务异常(db.SaveChanges() Exploding with Transaction Exception)

不知道为什么会发生这种情况,但如果您还检查了db.dlc_Products的Local集合,则db.dlc_Products第一个SaveChanges() : foreach (var product in dlc_products.ToList()) { var dlc_product = db.dlc_Products.SingleOrDefault(p => p.name == product.name) ?? db.dlc_Products.Local.SingleO...

db.SaveChanges始终提供以下内容:无法定义两个对象之间的关系(db.SaveChanges always gives the following :The relationship between the two objects cannot be defined)

确保您对此事务中的所有查询使用相同的ObjectContext实例。 Make sure that you are using the same instance of the ObjectContext for all the querys on this transaction.

参数超出EF中的db.SaveChanges()范围(Parameter is out of range on db.SaveChanges() in EF)

要存储1.0,您需要将数字声明为 [N15] NUMERIC (2, 1) NULL, 或者只是不宣布精确度。 请参阅: https : //msdn.microsoft.com/en-AU/library/ms187746.aspx The problem was with the EDMX. Only changes in database does not make it work. Since EDMX does not updates itself with the changes...

db.savechanges()不起作用(db.savechanges() is not working)

无法更新EntitySet,因为它具有DefiningQuery,并且元素中不存在元素以支持当前操作。 确保你的表有一个主键 ! 如果不添加主键并更新实体框架模型并再次运行。 资源: Unable to update the EntitySet because it has a DefiningQuery and no element exists in the element to support the current operation. Make sure that your table ...

实体框架Db.SaveChanges()不起作用?(Entity Framework Db.SaveChanges() not working?)

如果您使用DbContext两个不同实例(您命名为db变量),那么当您在与实体跟踪的上下文不同的上下文中调用SaveChanges时,将不会保存任何内容。 您首先需要使用Attach方法。 db.customer_images.Attach(item); db.SaveChanges(); 不过,我认为你的情况你可以避免附加步骤,如果你重构一下你的代码,并且不使用实体本身的DbContext。 If you are using two different instances of the DbC...

EF:db.SaveChanges()vs dbTransaction.Commit(EF: db.SaveChanges() vs dbTransaction.Commit)

是的,如果您明确地将您的上下文封装在诸如.Net的TransactionScope之类的事务中,则可以在调用.SaveChanges()调用之后从实体中检索自动生成的ID,而无需提交该作用域事务。 using (var tx = new TransactionScope()) { using (var context = new MyDbContext()) { var newEntity = populateNewEntity(); context.MyEntitie...

ASP MVC5-Custom要求验证在db.savechanges失败(ASP MVC5-Custom requiredif validation failing at db.savechanges)

这是因为在浏览器级别(Javascript验证)触发的验证看到当选择No时,它会通过验证。 但是,在服务器端,EF正在执行相同的验证。 在保存之前检查并查看person1在服务器端的值:如果为空或是,那就是问题所在。 在这种情况下,我为我的视图(你拥有的那个)创建了一个模型,为我的ORM(EF)创建了一个模型。 在EF模型中,不要放置RequiredIf属性。 在保存之前将模型(用于视图)转换为模型(用于EF)并且一切都应该是好的。 That is because the validation f...

实体框架SaveChanges被调用但它不起作用(Entity Framework SaveChanges is called but its not working)

您尚未提供模型,但在以下行中使用ref关键字: if (city.FromLat > city.ToLat) More.Swap(ref city.ToLat, ref city.FromLat); if (city.FromLng > city.ToLng) More.Swap(ref city.FromLng, ref city.ToLng); 清楚地表明FromLat , ToLat , FromLng和ToLng成员是字段 ,因此不映射到数据库列。 使它们成为属性并使用不同的代码进行交换...

我一直在尝试实现自定义登录,我将更新密码,但db.savechanges不能使用我的代码(i have been trying to implement custom login where i'll be updating the password but db.savechanges isn't working with my code)

密码更改时,未加载复杂类型,因此在更新密码时db.savechanges()不起作用,因此如果加载复杂类型(在这种情况下为地址),问题就解决了 while password change the complex types were not loaded so while updating he password db.savechanges() didn't work so if you load the complex types(addresses in this case) the pro...

mvc4 - db.SaveChanges() - 十进制值超出范围(mvc4 - db.SaveChanges() - decimal value out of range)

找到这两个线程之间的交易: 如何使用EntityFramework 4.1 CodeFirst阻止十进制值在保存时被截断为2个位置? EF Code First中的十进制精度和比例 具体应用此代码到我的: public class MyContext : DbContext { public DbSet<Metrics> Metrics { get; set; } protected override void OnModelCreating(DbModelBuilder mod...

相关文章

更多

千锋首发Swift视频教程

千锋Swift视频教程-7.Swift结构体.mp4 千锋Swift视频教程-13.代理反向传值.mp ...

Swift入门视频教程-尚学堂视频教程

最新Swift语言语法介绍,包括Swift流程控制语句、Swift各种构造函数、closure、泛型、 ...

lucene4.7 过滤Filter(六)

先介绍下查询与过滤的区别和联系,其实查询(各种Query)和过滤(各种Filter)之间非常相似,可以 ...

Guava Objects类详解

Objects.toStringHelper(s1)

java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter的解决方案

struts2.0.x到struts 2.1.2使用的核心 过滤器是FilterDispatcher, ...

一个较完整的关键字过滤解决方案(中)

问题远没结束 上篇文章提出的问题解决了没有?哦哦,我是指采取命名约定的方式来改变过滤行为。当然有问题 ...

lucene自定义过滤器

散仙前些日子写了两篇Lucene的插曲,分别是关于分词和分页的知识,虽然当成插曲写,但是其内容还是比较 ...

Solr4:利用Filter实现两组关键词组合查询

本文参考:Lucene4.1:利用Filter实现两组关键词组合查询 1. 需求 根据客户名称,查询 ...

利用Decommission从Hadoop集群中Remove节点

我们现有的Hadoop集群已经运行了一段时间了 由于集群中的服务器分布在2个不同的机房,受跨机房带宽的 ...

过滤器引起的classcastException

最近作一个系统,其中有这么一个业务。就是针对所有数据插入,都要进行编码过滤,保证不会出现乱码。 大概 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本