This is my object FTContent
class FTContent: NSManagedObject {
@NSManaged var content_id: String // Primary key
@NSManaged var title: String
}
in my class i have an Set which hold FTContent
element
var mySet: Set<FTContent>
After some operation mySet
contains 5 element of FTContent
Now i want element(FTContent
) from mySet
How can get the Element from Set?
A Set
is a Collection
and you can simply iterate over its elements:
for elem in mySet {
print(elem)
}
or access by subscripting:
for idx in mySet.indices {
let elem = mySet[idx]
print(elem)
}
But note that the order of elements in a set is unspecified (and can change if elements are inserted or deleted). So you might want to sort it into an array, for example:
// Swift 2.2:
let allElements = mySet.sort({ $0.content_id < $1.content_id })
// Swift 3:
let allElements = mySet.sorted(by: { $0.content_id < $1.content_id } )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With