title: Core data Relationship in swift
body: <p>I am working on iPhone application where I need to implement one to many relationship from one entity to another entity.I have export <code>NSManagedObject</code> subclass from coredata database but could not find relation accessors in core data model file like Objective-C. </p>
  
  <p>Although I'm able to set data in relationship <code>NSSet</code> but this only persist while iPhone app is running. Once I kill and restart the application I didn't get entity relationship for in fetch request from core data.</p>
  
  <p>I am not sure what I am doing wrong.  It will be great if anyone can tell me how to set data in <code>NSSet</code> relationship object. Any sample example will be a great help</p>
  
  <p>Here is my core data model files. One folder can content multiple content as folder detail</p>
  
  <pre><code>extension FolderContent {
  
      @NSManaged var contentID: NSNumber?
      @NSManaged var contentTitle: String?
      @NSManaged var contentType: String?
      @NSManaged var publishDate: String?
      @NSManaged var folderList: NSSet?
  
  }
  
  extension FolderList {
  
      @NSManaged var folderID: NSNumber?
      @NSManaged var folderName: String?
      @NSManaged var folderDetail: NSSet?
  
  }
  
  func updateFolderList()
  {
      // Initialize Fetch Request
      let fetchRequest = NSFetchRequest()
  
      // Create Entity Description
      let entityDescription = NSEntityDescription.entityForName(FOLDER_LIST, inManagedObjectContext: self.managedObjectContext)
  
      // Configure Fetch Request
      fetchRequest.entity = entityDescription
  
      do {
          let result = try self.managedObjectContext.executeFetchRequest(fetchRequest).last as! FolderList
  
          let content = result.mutableSetValueForKey("folderDetail")
          content.addObject(self.getContent())
  
            var folderContent:FolderContent = result.folderDetail?.allObjects.first as! FolderContent
          print(folderContent.contentTitle)
          self.save()
  
          print(result)
  
      } catch {
          let fetchError = error as NSError
          print(fetchError)
      }
  
  }
      func getContent()-&gt;FolderContent
  {
      let folderContent = NSEntityDescription.insertNewObjectForEntityForName(FOLDER_CONTENT, inManagedObjectContext: self.managedObjectContext) as! FolderContent
      folderContent.contentID = 1
      folderContent.contentTitle = "Sandeep"
      folderContent.contentType = "Product"
      return folderContent
  }
  </code></pre>