nsset

How to convert NSSet to [String] array?

限于喜欢 提交于 2021-02-17 22:54:13
问题 I have an NSSet of Strings, and I want to convert it into [String]. How do I do that? 回答1: I would use map : let nss = NSSet(array: ["a", "b", "a", "c"]) let arr = nss.map({ String($0) }) // Swift 2 let arr = map(nss, { "\($0)" }) // Swift 1 回答2: If you have a Set<String> , you can use the Array constructor: let set: Set<String> = // ... let strings = Array(set) Or if you have NSSet, there are a few different options: let set: NSSet = // ... let strings1 = set.allObjects as? [String] // or as

How to convert NSSet to [String] array?

青春壹個敷衍的年華 提交于 2021-02-17 22:54:03
问题 I have an NSSet of Strings, and I want to convert it into [String]. How do I do that? 回答1: I would use map : let nss = NSSet(array: ["a", "b", "a", "c"]) let arr = nss.map({ String($0) }) // Swift 2 let arr = map(nss, { "\($0)" }) // Swift 1 回答2: If you have a Set<String> , you can use the Array constructor: let set: Set<String> = // ... let strings = Array(set) Or if you have NSSet, there are a few different options: let set: NSSet = // ... let strings1 = set.allObjects as? [String] // or as

Adding elements on many-to-many relation

给你一囗甜甜゛ 提交于 2021-02-04 21:34:40
问题 I am making a project where (from the perspective of school) you can calculate each student average. You can register a student (first entity) on a screen and subjects (second entity) on another screen. Student has name, email, grade and average as atributes, and Subjects has name. They relate many-to-many with each other. I am trying to create a copy of subjects list to each student, then on each student i can register a grade to each subject. Like this: Model concept Model: !https://imgur

How to compare two NSSets based on attributes of objects?

杀马特。学长 韩版系。学妹 提交于 2020-01-23 09:55:26
问题 I have two nssets. nsset1: person.id = 1, person.id = 2, person.id = 3 nsset2: person.id = 1, person.id = 2 Results should be: nsset1 - nsset2: person (with id 3) nsset2 - nsset1: null These objects with the same id in those two sets are different objects, so I couldn't simply do minusSet. I want to do something like: nsset1: person.id = 1, person.id = 2, person.id = 3 nsset2: person.id = 4, person.id = 5 Results should be like this: nsset1 - nsset2: person (id 1), person (id 2), person (id 3

Comparing NSSets by a single property

纵然是瞬间 提交于 2020-01-22 16:11:17
问题 I'm trying to determine if two NSSets are "equal" but not in the sense of isEqualToSet. Items in the two sets are the same class but are not the same object, or even references to the same object. They will have one property that is the same though - let's call it 'name'. Is my best bet in comparing these two sets to do a simple set count test, then a more complex objectsPassingTest: on each item in one set, making sure an item with the same name is in the other set? I'm hoping that something

Comparing NSSets by a single property

て烟熏妆下的殇ゞ 提交于 2020-01-22 16:11:06
问题 I'm trying to determine if two NSSets are "equal" but not in the sense of isEqualToSet. Items in the two sets are the same class but are not the same object, or even references to the same object. They will have one property that is the same though - let's call it 'name'. Is my best bet in comparing these two sets to do a simple set count test, then a more complex objectsPassingTest: on each item in one set, making sure an item with the same name is in the other set? I'm hoping that something

How to search an NSSet or NSArray for an object which has an specific value for an specific property?

血红的双手。 提交于 2020-01-18 21:32:28
问题 How to search an NSSet or NSArray for an object which has an specific value for an specific property? Example: I have an NSSet with 20 objects, and every object has an type property. I want to get the first object which has [theObject.type isEqualToString:@"standard"] . I remember that it was possible to use predicates somehow for this kind of stuff, right? 回答1: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"type == %@", @"standard"]; NSArray *filteredArray = [myArray

NSDictionary, NSArray, NSSet and efficiency

冷暖自知 提交于 2020-01-10 09:04:29
问题 I've got a text file, with about 200,000 lines. Each line represents an object with multiple properties. I only search through one of the properties (the unique ID) of the objects. If the unique ID I'm looking for is the same as the current object's unique ID, I'm gonna read the rest of the object's values. Right now, each time I search for an object, I just read the whole text file line by line, create an object for each line and see if it's the object I'm looking for - which is basically

NSDictionary, NSArray, NSSet and efficiency

北战南征 提交于 2020-01-10 09:03:28
问题 I've got a text file, with about 200,000 lines. Each line represents an object with multiple properties. I only search through one of the properties (the unique ID) of the objects. If the unique ID I'm looking for is the same as the current object's unique ID, I'm gonna read the rest of the object's values. Right now, each time I search for an object, I just read the whole text file line by line, create an object for each line and see if it's the object I'm looking for - which is basically

NSDictionary, NSArray, NSSet and efficiency

独自空忆成欢 提交于 2020-01-10 09:03:26
问题 I've got a text file, with about 200,000 lines. Each line represents an object with multiple properties. I only search through one of the properties (the unique ID) of the objects. If the unique ID I'm looking for is the same as the current object's unique ID, I'm gonna read the rest of the object's values. Right now, each time I search for an object, I just read the whole text file line by line, create an object for each line and see if it's the object I'm looking for - which is basically