How to check which class/UIViewController is executing while testing on device on Xcode? - swift

Recently I have been working on an old swift project built in back in 2015. Its really difficult to find which ViewController is executing currently because of the naming convention, usage of really massive storyboard(I feel terrified to even go to the main.storyboard) and various reason like usage of different language. Of course I can find it but it takes long. I was thinking if there is any way like when I run the project on a device and navigate to different page is there any way to see in the console which ViewController is executing ?

There is a quick way to find what view controller you are on when you are running your app.
1) Launch your app on the device or simulator.
2) Go into Xcode and tap this button:
3) This will open the Debug View Hierarchy. Click on the phone and you will see all the elements in the top bar. You can also see a hierarchy on the left-hand side. In here, you can click down and you will see the name of the view controller on screen.

Using the debugger after putting a breakpoint where you prefer you can write this and press return.
Swift 4.x
po UIApplication.shared.keyWindow?.rootViewController?.value(forKey: "_printHierarchy")
This method is a private API, thus you cannot use on production code, just use it in debug or from the debugger console.

I think it is better to see in debug area for your current viewcontroller named self, you get all information from there open the dropdown and and see you need to put break point in your viewController init method or where you want to debug, However you want to know programatically which is you current viewController you can get it by
appDelegate.window.currentViewController()
If you need which ViewController is Pushed or presented you can get from the above code but the case will be different if you are using the Slidemenu controller, I mean it is totally depends on how you have started navigation and which navigation controller is currently is use.
Can you briefly describe why you need current ViewController so i can help you further.

Related

How come Xcode Stops letting me hook up IBOutlets after two Interface Controllers?

I was setting the IBOutlets for the first few objects of a Watch App.
However, after doing a few IBOutlets it stops once I get to work on the third InterfaceController, closes InterfaceController.Swift, and instead opens WKInterfaceController.h. It does this every time I try to add the label or button to the code.
Why is this? Should I be approaching this code differently if I'm trying to build a hierarchical program?
Thank you!
This is what I want, where I can add in the outlets...
But after a few outlets, it automatically opens this page and doesn't let me add anymore...
Do you mean the right-hand side of the split view showing the code doesn't load the correct class?
If so, it's probably the reasonably common issue of Xcode not automatically knowing which class to load.
You can select the class you want to show manually by clicking in the toolbar above the code (i.e. the "two circles" in the second screenshot right above the code), and selecting the correct file

Swift ViewController does not respond to -getFile, Could not connect action, target class

My code works all fine but there is always two console message every time I run it.
app works fine but the messages just bugs me so much. Could anyone tell me what is wrong with my code and what does these console message means,thanks
2016-06-13 14:31:15.014
LazyHackintoshGenerator[1625:37250] Could not connect action, target class
LazyHackintoshGenerator.ViewController does not respond to -getFile:
Select your ViewController.
Right-click on its “View Controller” icon (the blue circle with a white square inside).
Look for warning icons (yellow triangles).
Hover over them. An explanation of the problem will appear.
As Feldur said, the problem is probably a leftover link from your storyboard to a method that does not exist anymore (maybe you renamed it or deleted it manually). Remove the link by clicking on the cross, and, if needed, re-link to the appropriate method in your code.
Here is an example of what it will look like in Interface Builder.
Likely a control's action in your storyboard is linked to a method getfile that no longer exists

iPhone Beginner Question - Hooking Up Actions

I'm just starting out with iPhone development, and in my hello world application I'm having a hard time hooking up a view to a controller with actions. I followed the instructions in the book I'm reading (I believe), but depending on where I run the application the app behaves differently.
-When i command-r from the code, I see only the single button I have on the view taking up the whole window. When I click the button the action is triggered.
-when I command-r from the interface designer I see the button, label, and textbox lined up correctly. When I click the button nothing happens.
Anyone know why this is happening/how to fix it? Thanks.
Launching simulator from interface builder only simulates selected .xib file. You should only do that to test your view design.
If you want to learn the basics about iPhone development I recommend:
NewBoston: http://www.thenewboston.com/?cat=34&pOpen=tutorial
Stanford: http://itunes.stanford.edu/
both are free video tutorials on how to make iPhone apps.
Good luck!
you accidentally the whole view.
Seriously. You made one wrong connection. You connected the view outlet of the viewController (aka File's Owner) with the UIButton.
just delete this connection and connect the view outlet of the File Owner with the "Root"View.
And you should probably remove almost all connections that trigger btnClicked: too. TouchUpInside from the button is enough.
And you should follow the objective-c coding style (Part II) and start all Class names with a capital letter. chapter_2ViewController should be something like Chapter2ViewController.
To my knowledge you cannot run an app from interface builder, I may be mistaken.
You should make sure your interface builder file is saved and run the app from within xcode
just a guess, but is the window size in the simulator different than that in IB? You might check the control resizing masks and on the sizing tab in IB.

dismissModalView crash iphone app, but not with debugger on

I have an iphone app with a modal view. The app crashes when the modal view get dismissed.
As soon as the modal disappear at the bottom of the screen, and consequently the original view is shown behind, then the app crashes with no entry in console view.
I have tried to switch debugger on and I discovered that the app just run fine, with no crashes at all.
-First, I would like to know why such behaviour, shouldn't the debugger sit just on top without "disturbing" the app ?
-Second, without debugger, can you point out what should I look at to solve my problem ? Or if you encounter something similiar ? Please be as much specific you can, because I am not an expert in objective-c programming.
I don't know what details to give you, the app is a normal one with standard iphone component, but for start I can say the modal view (which is built with IB) is called inside a NavigationBar system.
thanks
When these types of things happen, it is almost always because of memory allocation issues. The first step I would take is to do a "Clean All" and a "Build and Analyze", and look at all the analysis warnings. Analyze is very good at finding basic "use before allocate", "use after deallocate", or "wrong number of retains/releases" types of problems.
The next step is to turn on "Zombie" detection mode, which looks for accesses on memory that has already been deleted (in other words, killed objects coming back from the dead.) To do this, get info on your executable, go to the Arguments tab, and add a "variable to be set in the environment" of "NSZombieEnabled" to value "YES". Then look in the console when you run to see if something looks off.
Finally, you might try creating a new configuration where you use all the release mode settings for optimization, but add debug symbols. Maybe that will shake up the allocation disbursement in memory enough to trigger the bug in debug mode.

Is it possible to turn a View-Based App into a navigation-Based App?

I am close to finishing my first application (a UITableView style one) on the iphone but have realised it will look much better, and stand a far better chance of getting through the approval process, if it is presented as a navigation-based app rather than a view-based one - in hindsight my initial choice is not really suitable...
Is it possible for me to somehow change easily the application into a new type, or would i be better starting again from scratch with all the hassle that would entail...
thanks for any advice on how it may be done,
karl
It wouldn't be particularly difficult to shift the means of interaction to a navigation controller from a simple view controller (it also isn't difficult to go the reverse direction). Although, there isn't anything as simple as a tutorial on how to do it or menu item you can select. You could look at the plumbing generated by Apple's template for a navigation based application and add the necessary glue to your app delegate. Once that is in place you could simply push your view based applications view controller onto the navigation stack. If you have more specific questions or are stuck somewhere in particular we can help to get you un-stuck if you provide details about where you are running into issues.
As an aside, I doubt your application will be rejected solely for being view based vs. navigation based.
Hmmmmm, for soem reason t wont let me add anything to comment on your post!
Anyway, i guess this is as good as anything here...
Ive been messing for the last hour or so and have managed to integrate my old code/data etc into a new navigation one without too many problems, in fact it looks nicer with a title bar at the top!
(I do like to try and work stuff out for myself so its a good learning curve!)
I am still struggling in that although the new view opens up i am
struggling to use a string from the first view (I have a UITableview table in there, i select a row and get a correct value from it which i currently check via an alert message) in the second view.
for some reason i do not get a title bar and 'back' button in the 2nd view so i guess it is not being put on the stack correctly (I have put a quick 'return' button in the view for testing purposes so i can navigate backwards and forwards).
Still, Im about 100% further on than i was earlier!
cheers for the reply,
Karl