I am new to swift/iOs and working on scene which is very similar to existing screen in the app.Here are my questions.
Can I copy the scene and make few changes to UI? If so, can you please list out the steps to copy?
If yes to above question, can I reuse the code in existing view controller or do I need to create new view controller and add new methods?
Hi @chakri, you can copy a scene by copy and pasting it in the storyboard. For example, if you have a view controller, you can select it then copy by going to Edit → Copy or cmdC. Then you can paste it by going to Edit → Paste or cmdV. You can also look at your “Outline Document” which should appear on the left of your storyboard (small square button next to "View as:…) to see if the new scene appears or by dragging the pasted scene into a new location of the storyboard.
As for reusing existing code in the existing view controller, I would recommend creating a new view controller file and assigning it to the newly copied view controller. I would also give it a new name as to not confuse Xcode with two of the same files. However, if you want to reuse code to have a similar functionality that could work as well (i.e. copying code and pasting it to new view controller file) and adjusting it to how you see fit.
I hope this clears up your questions. Happy coding!
@gdelarosa Thanks Gina! I like the idea of creating new VC for new scene. But I have concern on copying the same code between two VC. If both methods are doing the same job, I should be able to share the method/func between the classes. Do you see any issue creating instance on VC1 in VC2 and reusing the functions?
I don’t believe you would have any issues if handled properly. If you run across any issues with your implementation, feel free to ask for help here!
the only issues that you will face if you use a single VC between two classes are the linking of elements (IBOutlets) and if you want to share code between VC’s then you can use common functions.
you could have a generic VC that housed different views or generic methods. There are many possibilities and there is no right or wrong answer, it all depends on your app architecture and how you implement it.
This topic was automatically closed after 166 days. New replies are no longer allowed.