Author Topic: CoreData - Attributes  (Read 4783 times)

Froman

  • Newbie
  • *
  • Posts: 1
    • View Profile
CoreData - Attributes
« on: March 23, 2016, 05:08:35 PM »
Hello Kevin,

I have read all three books and have learned a lot, thanks for that. 

My question pertains to the attributes of core data and how to list them via UITableView. 

I am using the mmBusinessObject method for CoreData and am slowly understanding all the little nuances of it.

Here are my current Attributes below:

import CoreData

extension StationEntity {

    @NSManaged var icao: String
    @NSManaged var state: String
    @NSManaged var country: String

}

I am building a database with airport locations, I would like to incorporate a search function in the future, however for now all I want is to show on the FIRST UITableView is a list of countries.  How would I go about showing only 1 instance of each country in the first view controller.   At the moment I multiple instances of countries. 

Instead of self.stationList.count what would I use? 

Any help would be greatly appreciated. 

angelina

  • Global Moderator
  • *****
  • Posts: 25
    • View Profile
Re: CoreData - Attributes
« Reply #1 on: July 02, 2016, 09:16:14 PM »
The reason your showing duplicate countries is most likely because you have multiple airports that share the same country.  One way to show a list of countries in your table view without duplicates is to restructure your data model by creating a separate CountryEntity and a separate StateEntity.  Then set up your state and country attributes on your StationEntity as relationships. In the tableview you would get the list of countries directly from the CountryEntity so rather than using stationList.count you’d use countryList.count. Hope that helps.


Angelina
Oak Leaf Enterprises, Inc.