问题标签 [nsmutableset]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
103 浏览

ios - 为什么 containsObject 在 NSMutableSet 的 NSSet 副本上不起作用?

我在创建可变集的集副本时遇到问题,然后对于(新)集副本的 containsObject 失败。例如:

NSString *sameID = @"XYZ";

然后在主线程/有时在不同的线程上:

然后在后台线程上,总是在(我已经通过记录验证)添加了sameID之后:

看到有断点:

我已经测试了相同 ID 字符串没有额外或隐藏的空格。AFAIK containsObject 用于包含 NSString 的集合使用 isEqual 如果字符串具有不同的指针,这无关紧要,对吧?

编辑:一些附加信息:添加到 mutableSet 的 NSString 发生在不同的线程上,但总是在创建 newSet 副本之前发生。创建和检查 newSet 是在后台线程上完成的,这就是我复制 mutableSet 的原因(我在日志记录中看到这总是在向 mutableSet 添加字符串之后)。所以我在日志语句中看到字符串(sameID)已添加到 mutableSet,然后在后台线程上我将 mutableSet 复制为一个集合并快速检查该集合是否有相同的字符串(sameID),但它不存在。

Edit2:我已经测试了下面的代码并且它通过了,但是当我尝试实现与上述相同的解决方案时,它仍然具有相同的结果(mutableSet 包含字符串但 newSet 不包含)。

0 投票
1 回答
66 浏览

objective-c - 在 macOS Objective-C 应用程序中,我将 NSMutableSet 子类化为强制执行不同于 isEqual 的相等性。我的实施好吗?

在我的 macOS Objective-C 应用程序中,我创建了 NSMutableSet 的子类。我想要实现的是一个不使用 isEqual: 作为比较策略的 NSMutableSet。具体来说,该集合将包含 NSRunningApplication 类型的对象,并且我希望该集合基于对象捆绑标识符的相等性工作。以下是我的实现:

头文件:

实现文件:

这似乎有效,实际上,当适用时,Xcode 记录普通 NSMutableSet 不会认为两个成员相等。我想把这个实现带到生产应用程序中,但恐怕我没有考虑重要的事情,因为这是我第一次继承 NSMutableSet。例如,我担心以下方法:

这是我对 backStorageMutableSet 的唯一使用,因为其余的都支持到数组中。这很好还是会带来麻烦?子类的其他部分会不会带来问题?任何帮助将不胜感激。谢谢

0 投票
1 回答
99 浏览

swift - 使用 Swift Combine 检测 NSMutableOrderedSet 的变化

我正在尝试使用 combine 观察 ViewModel 中 NSMutableOrderedSet 的变化。我想知道何时添加或删除 NSMutableOrderedSet 的某些元素

我的 ViewModel 的一些代码:

这是我在 ViewModel 中用来向 NSMutableOrderedSet 添加元素的函数:

我有一些其他发布者与其他类型(自定义类)合作良好。

我错过了什么 ?

0 投票
1 回答
26 浏览

class - Referencing / Accessing a MutableSets-Items-name in a class with different variables(Strings and Sets) in a textbased game of a total Kotlin noob

I am a total noob when its about Kotlin, but I think it is fun to use and in my free time, I am trying to learn it. I got some books and went through them and based on that, to get more practical experiences, I am trying to create a little text-based adventure in the Kotlin JVM, like Zork. There should be different rooms and each room should have some items, that can be looked at and taken (later wanna implement that you can use them). My Problem is: The user should input "take {name of item in that room} in the console. But i am unable to reference the name of the item of the mutable list of the cellar. All internethelp only have some easy examples, so I couldnt find a solution to this. All i can let the console do is "room.name" so then he gives me the name of the room. But i dont want to get the name of the room, i want to get the name of the Item in that room. Can somebody please help me?