0

This is my first post about Swift and I hope someone can help me. I'm a junior Ruby/Rails developer and have recently started building an app for a personal project to get to grips with developing in Swift and XCode, as it is something I am interested in moving into.

I have just started building my app, but have hit a problem almost straight away that I have been unable to find a clear answer to or any guidelines that I can bend to serve my purpose. I'm sure it must be a fairly simple issue to solve, so I'll try and write my problem as clearly as possible:

If I want to take some user input from a text field, such as a name or a location, and then display that input in another view controller, how would I go about doing it?

So far in my app, a user is presented with a button, which when pressed, shows a view controller with two text fields. I want to take the input strings from the two text fields and display that data in a label on the next view controller, so the user can add more information to the object before publishing it to be displayed in a table view cell elsewhere in the app. I have used IBOutlets on the text fields.

I have been reading about Core Data in Swift and have worked through a couple of tutorials about adding data to a table view, including the Start Developing iOS Apps (Swift) from Apple and I think I'm on the right track to finding out how to achieving the functionality I want. But I'm not entirely sure, and wanted to ask if I am on the right path or if I'm going about it the wrong way?

If anyone could link me to any tutorials or guides or point me in the right direction so that I can figure out what seems like a basic step of storing data that can be retrieved and displayed in other view controllers, I would appreciate it very much.

Thank you in advance.

2 Answers2

0

You may do it by many ways -

  1. If you want to take input string to the immediate next UIViewController, then when you navigate to another UIViewController , initialise two string object of that view from current UIViewController and then navigate. In that UIViewController you can have your string.

  2. If you want to use those strings in some other UIViewController then you can take two string variable in AppDelegate(That is a global class) and set them from current UIViewController and you can use them whenever you want.

  3. If you want to permanent save that data then you can better use NSUserDefaults ( NSUserDefaults - storing and retrieving data )if it is only 2 or 3 or some little amount of field data. If data is more you can use database.

Community
  • 1
  • 1