title: One to Many doesn't differentiate within groups in SwiftUI
body: <p>I am trying to build an app in which users can create groups and create individual Posts within those groups which, at the end, will lead to the specific PostDetailsView. So: Post in Group A is different to Post in Group B.
  I tried to implement by following a tutorial with One To Many. however, after following the steps carefully, the groups still display the same content.</p>
  <p>Structure: Groups -&gt; post -&gt; ...</p>
  <p>This is an exhibit from my Group+CoreDataProperties:</p>
  <pre><code>extension Groups {
  
  @nonobjc public class func fetchRequest() -&gt; NSFetchRequest&lt;Groups&gt; {
      return NSFetchRequest&lt;Groups&gt;(entityName: &quot;Groups&quot;)
  }
  
  @NSManaged public var groupThumbnail: Data?
  @NSManaged public var groupTitle: String?
  @NSManaged public var id: UUID?
  @NSManaged public var posts: Set&lt;Posts&gt;?
  
  public var postsBind: [Posts] {
      let setPosts = posts
      return setPosts!.sorted {
          $0.id &gt; $1.id
      }
  }
  </code></pre>
  <p>This is my SetUp for HomeView:</p>
  <pre><code>@Environment(\.managedObjectContext) private var viewContext
  
  @FetchRequest(entity: Groups.entity(), sortDescriptors: [
      NSSortDescriptor(keyPath: \Groups.groupTitle, ascending:true),
      NSSortDescriptor(keyPath: \Groups.groupThumbnail, ascending:true),
      NSSortDescriptor(keyPath: \Groups.id, ascending:true),
  ])
  
  var groups: FetchedResults&lt;Groups&gt;
  </code></pre>
  <p>This is an exhibit of how I present groups on HomeView:</p>
  <pre><code>LazyVStack (spacing: 20) {
                      ForEach(groups, id:\.self) { Group in
                          NavigationLink(destination: GroupView()) {
                              ZStack (alignment: .bottomLeading) {
                                  
                                  Image(uiImage: (UIImage(data: Group.groupThumbnail ?? self.image) ?? UIImage(named: &quot;defaultGroupThumbnail&quot;))!)
                                      .resizable(capInsets: EdgeInsets())
                                      .aspectRatio(contentMode: .fill)
                                      .frame(height: 200, alignment: .center)
                                      .cornerRadius(22)
                                  
                                  VStack (alignment: .leading) {
                                      
                                      Text(&quot;\(Group.groupTitle ?? &quot;Untitled&quot;)&quot;)
                                          .font(.title)
                                          .fontWeight(.heavy)
                                          .multilineTextAlignment(.leading)
                                      
                                      Text(&quot;Consists of 5 Posts&quot;)
                                  }
                                  .padding([.leading, .bottom], 18.0)
                                  .foregroundColor(.primary)
                              }
                          }
  </code></pre>
  <p>This is an exhibit of the Setup of the CreateGroupView:</p>
  <pre><code>@State var image : Data = .init(count: 0)
  
  @Environment(\.managedObjectContext) private var viewContext
  @Environment(\.presentationMode) private var presentationMode
  
  @FetchRequest(entity: Groups.entity(), sortDescriptors: [
      NSSortDescriptor(keyPath: \Groups.groupTitle, ascending:true),
      NSSortDescriptor(keyPath: \Groups.groupThumbnail, ascending:true)
  ])
  
  var groups: FetchedResults&lt;Groups&gt;
  </code></pre>
  <p>This is an exhibit of how I pass in the details when creating Groups on external View:</p>
  <pre><code>.toolbar {
                  ToolbarItem(placement: .navigationBarTrailing) {
                      Button(&quot;Done&quot;){
                          //addGroup()
                          let send = Groups(context: self.viewContext)
                          send.groupTitle = self.groupName
                          send.groupThumbnail = self.image
                          send.id = UUID()
                      
                      try? self.viewContext.save()
                      self.presentationMode.wrappedValue.dismiss()
                      self.groupName = &quot;&quot;
                  }
              }
              ToolbarItem(placement: .navigationBarLeading) {
                  Button(&quot;Cancel&quot;) {
                      self.presentationMode.wrappedValue.dismiss()
                  }
                  .foregroundColor(.red)
              }
          }
  </code></pre>
  <p>This is an exhibit of the Setup of the CreatePostView:</p>
  <pre><code> @Environment(\.managedObjectContext) private var viewContext
      @Environment(\.presentationMode) private var presentationMode
  
  @FetchRequest(entity: Posts.entity(), sortDescriptors: [
      NSSortDescriptor(keyPath: \Posts.postsTitle, ascending:true),
      NSSortDescriptor(keyPath: \Posts.postsThumbnail, ascending:true)
  ])
  
  var post: FetchedResults&lt;Posts&gt;
  </code></pre>
  <p>Exhibit of what I pass in when creating Posts:</p>
  <pre><code>.toolbar {
                  ToolbarItem (placement: .navigationBarTrailing){
                  Button(&quot;Done&quot;){
                      let send = Posts(context: self.viewContext)
                      send.postsTitle = self.postsName
                      send.postsThumbnail = self.image
                      send.id = UUID()
                  
                  try? self.viewContext.save()
                  self.presentationMode.wrappedValue.dismiss()
                  self.postsName = &quot;&quot;
              }
              }
              ToolbarItem (placement: .navigationBarLeading) {
              Button(&quot;Cancel&quot;) {
                  self.presentationMode.wrappedValue.dismiss()
              }
              .foregroundColor(.red)
              }
          }
  </code></pre>
  <p>This is the Setup of the PostsView, where all Posts are presented:</p>
  <pre><code>@Environment(\.managedObjectContext) private var viewContext
  @Environment(\.presentationMode) private var presentationMode
  
  @FetchRequest(entity: Posts.entity(), sortDescriptors: [
      NSSortDescriptor(keyPath: \Posts.postsTitle, ascending:true),
      NSSortDescriptor(keyPath: \Posts.postsThumbnail, ascending:true),
      NSSortDescriptor(keyPath: \Posts.id, ascending:true)
  ])
  
  private var posts: FetchedResults&lt;Posts&gt;
  </code></pre>
  <p>This is an exhibit of how I present Posts:</p>
  <pre><code>LazyVGrid( columns: twoColumnGrid, spacing: 16) {
                      ForEach((post), id: \.self) { Post in
                      
                      VStack (alignment: .leading) {
                          ZStack (alignment: .bottomLeading) {
                              
                              Button(action: {
                                  self.isPresentingPostDetailView.toggle()
                              }, label: {
                                  Image(uiImage: (UIImage(data: Post.postThumbnail ?? self.image) ?? UIImage(named: &quot;defaultGroupThumbnail&quot;))!)
                                      .resizable(capInsets: EdgeInsets())
                                      .aspectRatio(contentMode: .fill)
                                      .frame(width: 165, height: 165)
                                      .cornerRadius(22)
                                      .scaledToFill()
                              })
  </code></pre>
  <p>I hope this is not too long. I don't exactly know where the problem is and what you might need. I have been trying for a few hours now. But nothing seems to solve my problem.
  Any help is appreciated.</p>
  <p>Thanks and Kind Regards</p>