New Swift Application Creates Obj C Files - ios

I am a bit new to iOS development. Am I going crazy here?
I am using xCode to create a paged application. I select new project with the language as swift.
When I go to add a new view to the application it adds a view with Objective C?? Why? I want to use Swift. Am I doing something wrong?
Adding more screenshots, how do I get the second view to show me the Swift code instead of the "UIKit" code?
Working Side...
Not working
3:

It looks like your Assistant Editor is automatically opening the underlying Objective-C header files rather than the Swift files associated with your View Controllers. Try clicking on Automatic at the top of the Assistant editor, then hovering for a moment to see if your Swift file comes up (it should appear above or below the UIViewController.h file).
If you haven't created a subclass for the View Controller you've created in the storyboard, you'll need to do that first, then assign that class to the View Controller in the storyboard. To do this, select File > New > Fileā€¦, select Cocoa Touch Class, and make it a subclass of UIViewController (don't create a XIB file). Then, in your storyboard, click on your newly-created View Controller (you can select it from within the view hierarchy on the left), open the Identity inspector, and set its Class to the subclass of UIViewController you just created.
If, for some reason, you've created a View Controller class and correctly associated it with the storyboard object and it's still not appearing, you can use the Manual selection in the Assistant editor to drill down to the file you want to appear.

Related

How to create a view controller file after creating a new view controller? (xcode 8.21)

I'm trying to develop a tabbed activity app in xcode 8.21, and it only starts you out with two tabs. I want to make a third tab. I followed an online tutorial by adding another view controller and linking it to the tab bar controller. However, it doesn't automatically create a ViewController.swift file. All the tutorials are out of date (already), so I tried manually creating a .swift file called ThirdViewController.swift. Then, in the custom class section of the view controller, I tried typing ThirdViewController but it didn't work. Please help, I don't know what I'm doing wrong. Every tutorial I've seen online is already outdated.
You chose the wrong path to generate your file. In Xcode select "Cocoa Touch Class" instead of "Swift File" you can then decide if you want a Swift or Objective-C file with a specific Class (UIViewController in this case)

Swift Input and event handling for storyboards

I've been trying to outline the basic functionality of a swift application I was developing. I created a basic gui with the storyboard functionality that xcode provides. Here is a picture of what it looks like currently:
What I want to do next is code up a way to receive and store input from the text fields I outlined in the storyboard. Additionally I want to receive information regarding certain settings that are placed from the switches I outlined in the second screen.
I've been looking through the files that xcode provides me but I haven't been able to find the one that contains the functionality for the storyboards. If someone could point me in the right direction for that i would greatly appreciate it. Ultimately I just want to be able to manage the input provided by the interface I outlined below. Thanks!
For each view controller on the storyboard make a subclasses of UIViewController.
In the inspector panel on the left of the storyboard set the class of each view controller to their respective subclass of UIViewController.
Open up the .swift file for that view controller and storyboard and ctrl + drag from the textField to the class this will cause a small popup where you can create an IBOutlet or IBAction.

how to work with multiple viewcontroll and use the viewcontroll.h and m file

I am new with xcode.
I used one viewcontroller and coded it in the viewcontriller.h and .m files.
My problem is when I add more viewcontrollers, I can't create more action from the new viewcontrollers to the basic files (viewcontroller.h and .m).
For example to right click and drag swipe recognizer from new viewcontrollers to the viewcontroller files (h&m files) in interface builder.
As my comment seems to be the answer, I'll add it as an answer:
I suspect you do want to set the class of the newly added view controllers in interface builder to the class of the view controller you want it to be.
Then, you can drag-connect like with the first one, xcode did set up for you initially.
Also, do remember to use different view controllers for different purposes (you might have to create another subclass of UIViewController).

Xcode new scenes and classes [duplicate]

I'm just starting out in xCode 6, and I can't seem to figure out how to add a new swift-file to the new view controllers I add in the interface builder.
Any tips on how to proceed would be appreciated.
Add a new Cocoa Touch class. Choose File->New->File... from the menu. Give this new class a name such as "ViewController2" and set the Subclass of: pop down to UIViewController. The file "ViewController2.swift" will be created.
Click on your new View Controller in Interface Builder. In the Identity Inspector (on the right in Xcode) set the Custom Class for the View Controller to "ViewController2".
If your custom class isn't showing up in the Identity Inspector, your files may have been moved or saved in the wrong folder. I would delete them from your project and try again, this time letting the files be saved wherever they are automatically. Good luck!

can I create a .xib from an implementation file?

I have a project that has the header and the implementaiton files and loads a plain old UITableViewController from the .m but I have no way of configuring the View (I would like to do stuff like ad buttons and text fields onto the view instead of just having a table), should I create a .xib file so that I can modify the view? (Reason I don't just start a new project is that the current project has a bunch of other stuff like OAUTH processes that kick off at the AppDelegate stage to log a user into a system - and I need this functionality). So my question how can I create a .xib from the existing .m .h files and then add other objects which I can then code for.
An answer from this similar question:
"Here's a more step-by-step way to associate your new UIViewController and .xib.
Select File's Owner under Placeholders on the left pane of IB. In the Property Inspector(right pane of IB), select the third tab and edit "Class" under "Custom Class" to be the name of your new UIViewController subclass.
Then ctrl-click or right-click on File's Owner in the left pane and draw a line to your top level View in the Objects portion of the left pane. Select the 'view' outlet and you're done.
You should now be able to set up other outlets and actions. You're ready to instantiate your view controller in code and use initWithNibName and your nib name to load it."
If it's a UITableViewController, simply create a new XIB file via Xcode (File -> New -> iOS -> UserInterface -> View) and then add set the file's owner to your subclassed UITableViewController.
You'll likely want to re-do how the user interface looks -- in terms of dropping objects like the table view and buttons or whatever else -- into the XIB's view. It'll certainly save a lot of time versus trying to debug programmatically creating and adding subviews and actions.
And once that's in place, you can then make IBOutlets and IBActions to your heart's content.

Resources