nsorderedset

How to covert NSMutableOrderedSet to generic array?

Deadly 提交于 2020-02-23 09:14:51
问题 I have this for loop, p is a NSManagedObject , fathers is a to-many relationship, so I need to cast NSMutableOrderedSet to [Family] but it does not work, why? for f in p.fathers as [Family] { } 回答1: You can obtain an array representation of the set via the array property - then you can downcast it to the proper type and assign to a variable: let families = p.fathers.array as [Family] but of course you can also use it directly in the loop: for f in p.fathers.array as [Family] { .... } 回答2: The

How to implement a Mutable Ordered Set generic type formerly known as NSMutableOrderedSet in native Swift?

前提是你 提交于 2020-01-29 04:13:10
问题 The bounty expires in 7 days . Answers to this question are eligible for a +250 reputation bounty. Leo Dabus is looking for an answer from a reputable source . I am trying to implement a generic Mutable Ordered Set type and it needs to conform to many protocols to behave the same way as an Array and a Set does in Swift. First of all to accomplish that the generic type element needs to conform to Hashable and the generic struct needs to conform to RandomAccessCollection, SetAlgebra,

Getting a String value from NSOrderedSet using SwiftUI ForEach

独自空忆成欢 提交于 2020-01-25 08:34:11
问题 Using this question/answer I am able to use ForEach to use a NSOrderedSet created from a One to Many relationship in CoreData, however I can't seem to access a String Attribute stored in the Core Data entity. I have two CoreData entities: Client & SessionNote. Clients can have many SessionNotes, the NSOrderedSet of clientNotes, and SessionNote can only have one Client. Client+CoreDataClass.swift: public class Client: NSManagedObject { } Client+CoreDataProperties.swift: extension Client {

Iterating over an NSOrderedSet

不打扰是莪最后的温柔 提交于 2020-01-12 12:26:32
问题 I'm trying to iterate over an instance of NSOrderedSet. Something like this: func myFunc() { var orderedSet = NSOrderedSet(array: [ 42, 43, 44]) for n in orderedSet { NSLog("%i", n) } } ...however the for loop line produces this compiler error: 'NSOrderedSet' does not have a member named 'Generator' Now I could convert it to an array like this: for n in orderedSet.array { NSLog("%i", n) } ...but I wondered if there was a better solution? I'm also keen to understand why it's possible to

Iterating over an NSOrderedSet

断了今生、忘了曾经 提交于 2020-01-12 12:26:11
问题 I'm trying to iterate over an instance of NSOrderedSet. Something like this: func myFunc() { var orderedSet = NSOrderedSet(array: [ 42, 43, 44]) for n in orderedSet { NSLog("%i", n) } } ...however the for loop line produces this compiler error: 'NSOrderedSet' does not have a member named 'Generator' Now I could convert it to an array like this: for n in orderedSet.array { NSLog("%i", n) } ...but I wondered if there was a better solution? I'm also keen to understand why it's possible to

NSManagedObject unrecognized selector sent to instance

淺唱寂寞╮ 提交于 2019-12-11 07:36:10
问题 I have a Core Data model as follows, where children is a to-many relationship. .h @implementation MyEntity @dynamic name; @dynamic children; @end .m @interface MyEntity : NSManagedObject @property (nonatomic) NSString *name; @property (nonatomic) NSOrderedSet *children; @end I then try to set it using: MYAppDelegate *delegate = (MYAppDelegate *)[UIApplication sharedApplication].delegate; NSManagedObjectContext *managedObjectContext = [delegate managedObjectContext]; NSEntityDescription

Protocol bridging NSMutableSet and NSMutableOrderedSet together

旧街凉风 提交于 2019-12-11 05:17:35
问题 In Swift 3 , I would like to be able to create a protocol which allows me to add elements and iterate through using for element in . The protocol should works on both NSMutableSet and NSMutableOrderedSet (since they do not inherit from the same class). I know there are good reasons why NSMutableSet and NSMutableOrderedSet do not inherit from the same class, it is explained here and here. But I want to create a protocol which only makes use of a fraction of all the methods inside NSMutableSet

NSOrderedSet and SwiftUI ForEach

喜欢而已 提交于 2019-12-11 04:52:58
问题 I am trying to work with CoreData and SwiftUI and have two entities; Dog and Walk. It is a one-to-many relationship between Dog public class Dog: NSManagedObject, Identifiable { @NSManaged public var name: String? @NSManaged public var walks: NSOrderedSet? } and Walk public class Walk: NSManagedObject, Identifiable { @NSManaged public var date: Date? @NSManaged public var dog: Dog? } The problem I am having is displaying all of the walks for a selected dog in a List. The following WalksView

Iterating over an NSOrderedSet

纵饮孤独 提交于 2019-12-03 22:41:09
I'm trying to iterate over an instance of NSOrderedSet. Something like this: func myFunc() { var orderedSet = NSOrderedSet(array: [ 42, 43, 44]) for n in orderedSet { NSLog("%i", n) } } ...however the for loop line produces this compiler error: 'NSOrderedSet' does not have a member named 'Generator' Now I could convert it to an array like this: for n in orderedSet.array { NSLog("%i", n) } ...but I wondered if there was a better solution? I'm also keen to understand why it's possible to iterate over a set but not an ordered set? NSOrderedSet implements NSFastEnumeration , so it should work

How to add element to NSOrderedSet for Core Data?

断了今生、忘了曾经 提交于 2019-12-03 06:20:38
问题 I did some studies on this post. But none of its solution work for me. Let me explain what I did: It's actually very similar with the mentioned post. Category.h @class Category, Item; @interface Category : NSManagedObject @property (nonatomic, retain) NSString * name; @property (nonatomic, retain) NSOrderedSet *items; @property (nonatomic, retain) Category *parentcategory; @property (nonatomic, retain) NSSet *subcategories; @end @interface Category (CoreDataGeneratedAccessors) - (void