Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
167 views
in Technique[技术] by (71.8m points)

ios - Swift: Relationship between 3 Entities to store Waypoint Array

My question is about relationships between 3 entities... (Task, Waypoint, Airport)
The goal is to save Tasks with Waypoints (in this case Airports)

First time i tried to realize this was to create a one-to-many relationship from Task to Airport

Task -> airports (to many) -> Airports

This works great so far... but in my case not useful. Cause the Airport Objects are unique i cant add them twice or more. But if you want to got to the startpoint again you have to add the first Airport as last Airport too. So i had to add an intermediate entity named Waypoint which holds the Airport Object.

Task -> waypoints (to many) -> Waypoint
Waypoint -> airport (to one) -> Airport

relationship 3 entities

But when i use it this way and try set the waypoint1.airport it gives me an error:
unrecognized selector sent to instance

let allAirports = editContext.fetchObjects(forEntityClass: Airport.self,
                                                       sortByKeypath: Airport.Attributes.name)

if let waypointsInTask = self.task.waypoints as? NSMutableOrderedSet {

 let waypoint1 = Waypoint()
            
 waypoint1.airport = allAirports.first
            
 waypointsInTask.add(waypoint1)

 for case let waypoint in waypointsInTask {
                
 print(waypoint)

}
}

Maybe iam getting it wrong... any hint?

question from:https://stackoverflow.com/questions/66046349/swift-relationship-between-3-entities-to-store-waypoint-array

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...