-2

I am trying to make an event planning app where the user enters various entries to plan an event (eg: title, location, when, etc). Users have options to choose from different themes, such as, birthday party, graduation party, house party, baby shower, etc.

I am using different view controllers for each theme. I am using my viewController.swift file to show data in a tableview. and for my other viewControllers, I have cocoa-touch files assigned to each of them.

Now let's pretend a user wants to plan a house party. First user will click on the house party button. That will direct the user to a different viewController (houseParty.swift). Here, user will be able to enter all the data necessary to organize the event (title, location, when, why, etc). Everything will be stored in an arrays of each type, meaning, Titles will have a different array, location will have a different array, etc.

Now, I want to be able to access those arrays in my viewController.swift file to preset those data in a tableview cell. How do i do that? I am making an object/instance of a class houseParty.swift in viewController.swift file and trying to access arrays but I am unable to do so.

var house = houseParty()
house.arrayName // Getting error here. It wont recognize an array from that file.
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Kunj Patel
  • 75
  • 3
  • 11
  • 1) To pass data between viewcontrollers see [here](https://stackoverflow.com/documentation/ios/434/passing-data-between-view-controllers#t=201611291641371551834) and [here](http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers). 2) house doesn't have arrayName Property. 3) I recommend you also wrap things into a `Struct` not into an Array. See [here](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/ClassesAndStructures.html) and [here](https://www.raywenderlich.com/116714/swift-tutorial-introducing-structures) – mfaani Nov 29 '16 at 16:44
  • 1
    This is an overly-broad 'How do I write programs in general?' kind of question that is highly frowned upon at StackOverflow. You're expected to educate yourself about the basics and get further into implementation, and then come here, if necessary, after due diligence, and ask specific focused software questions when there are no answers readily available elsewhere. – clearlight Nov 29 '16 at 17:05

1 Answers1

0

I recommend designing a single data structure for every different type of event. It could look something like:

    struct KPEvent {
        var eventType: EventType
        var time: String
        var location: String
        etc. 
     }

You can then store these in one array. This struct can drive your table view UI.

scord
  • 1,375
  • 1
  • 17
  • 34