I am new to Xcode so I didn't get how to resolve this error by reading other articles in StackOverflow related to this. Basically I am working on the CoreData part and the following code accesses Amount, Bank Name and Title field but it's giving this error.
The first four lines in your code are outside any context. You can't do that. No executable code can appear except inside a function — usually, some method of some class.
So those four lines need to be inside the ViewController class, not before it, and again, not just loose inside it, but in some method of the ViewController class.
Related
I'm trying to make a category for a class that gets defined in a source file I don't have access to, namely RunnerViewController.
The two important files here are iPad_RunnerAppDelegate.h and FilesBrowser.mm. I do not have access to the header file's corresponding source file.
iPad_RunnerAppDelegate.h contains a forward declaration to the RunnerViewController class, and can reference that class with no difficulties.
However, if I try to #include "iPad_RunnerAppDelegate.h" in FilesBrowser.mm and then try to create a category in the same file, it doesn't recognise the class name.
Despite this error appearing, I can still use the RunnerViewController class inside FilesBrowser.mm, I just can't make categories for it.
What's happening here, and how would I fix it?
I've had to do this same thing but it was a long time ago. The problem is that without some indication of where to apply the category, your code cannot work alone. What you need is info to the compiler to let it know where it's going to insert the category.
In FilesBrowser.mm, you will tell it by adding this BEFORE "iPad_RunnerAppDelegate.h":
#interface RunnerViewController: UIViewController // or whatever it actually subclasses
#end
Now the compiler knows that its going to insert the category against an Objective C class named RunnerViewController.
But - you're not completely done. Now you need to insure that the runtime / loader do the class loading and category insertions at the proper time. This is where my knowledge gets a bit fuzzy, so it may not turn out to be a problem at all.
What I believe needs to occur is for the RunnerViewController class to get loaded first, then later at some point the category you wrote applied to it (but this may not be necessary). So if RunnerViewController is statically linked into your app (using a .a archive), then you're good for sure. But if that class is in a dylib loaded dynamically, and your category is statically linked - well that might be a problem. I just don't know how long Apple waits to try and deal with the categories (which by the way the -ObjC link flag is for.
In any case try the code above first and just see what happens. If RunnerViewController is dynamically loaded, and you get some hard runtime error, there is a workaround where you would make your category go into a module/framework that is also dynamically linked, but gets linked after RunnerViewController.
In the end I believe you have a good chance of making this happen.
Have app in App Store running fine. New version adds a bunch of calculations and minimal new interface. During dev and testing, runs (seemingly) perfectly in Simulator on all devices. Started testing on physical devices, and getting Bad_Access 1 or 2. I read every link on those I could find, and realize it's a difficult error. Using Swift, so no specifically dereferenced pointers of the type mentioned in most links.
Refactored code in many ways over last week. Eventually got it as simple as possible, posted here. My AppDelegate.swift is as basic as possible with no extra stuff or app-specific processing/initialization. The storyboard entry point is a collection view controller of type MainCollectionViewController. In the viewDidLoad method of that controller, the very first statement is a function call to getDrawingInstructions() with parameters. Using default parameter values, and the first two parameters are structs full of CGFloat, Bool, and UIColor.
As you can see, it's crashing as it gets to that func before even entering the func and executing the func's code. The first func call from viewDidLoad of the initial vc.
I've cleaned the build folder and restarted XCode, I'm Swift 5 compliant, I've updated to XCode 11 GM, I've turned on zombies and have no console message. Looking for suggestions on what to try next, 'cause I'm stumped on how I could get screwed up addresses before (seemingly) executing any app-specific code. And remember, this part runs in Simulator and is unchanged from the prior version that ran fine on all devices.
(In different iterations of code, Zombies would yield a console message like objc[7801]: Class _NSZombie_FBSXPCMessage is implemented in both ?? (0x162585890) and ?? (0x162576dd0). One of the two will be used. Which one is undefined. That gives me no clue where to look, especially with the ??.)
Thank you for any insights.
Edit: Per suggestions, removed parameters from function (into struct), but the result was the same as before.
Edit: Removed first argument to the call, a large struct, and got same result. Also got console message: objc[8038]: Class _NSZombie__NSCallStackArray is implemented in both ?? (0x163481590) and ?? (0x163480750). One of the two will be used. Which one is undefined. Not sure how to use this message.
Edit: If the called func is a stub that returns immediately, it is safely processed. So...it's not even entered with a trace if there's code, but it processes if there's an immediate return. Confusing.
Edit: Reconfigured yet again to remove all arguments to the function and just initialize them with default values in the function. That crashes with the same error at the same place, the entry point to the function, without reaching any of the initialization statements in the function. So the first statement in viewDidLoad of the primary VC calls a func with no arguments and crashes with a dereferenced pointer or similar memory error without stepping into that func. I'm not sure how to make that even intentionally happen.
I ran my Swift 4.2 project in the simulator successfully. When I stopped the simulator, changed some small code, and began again, the entire project exploded. I reverted back the small code change. But the entire project still is broken.
Not from the code change, as my code change was setting a bool to true, but it appears as if something fundamental has broken.
Errors like:
Use of undeclared type 'ViewController'
Value of type 'ViewController' has no member 'view' Use of unresolved identifier 'performSegue'
Value of type 'ViewController' has no member 'present'
'super' members cannot be referenced in a root class
Method does not override any method from its superclass
Value of type 'ViewController' has no member
'setNeedsStatusBarAppearanceUpdate'
Protocol requires property 'hash' with type 'Int'; do you want to add the stub?
I have commented out just about every class.
I even started a completely new project, imported my classes, ran it successfully, stopped the simulator and immediately started again and the exact same thing happened.
I am unsure at why this is happening. Anyone have any suggestions? At this point I don't even know what to Google.
You are getting the use of undeclared type ViewController error because there is no type called ViewController. It should be UIViewController.
Many of the other errors depend on this very fact - Since ViewController is not a type within the Cocoa Touch Framework, the class is non-existent and thus does not have any of those properties that you et in the other errors.
Of course, without seeing any of your code it is hard to locate the culprit, but the fact that you are declaring your viewController as being of type ViewController instead of UIViewController is probably a big part of it.
I have been stumped on this for awhile. I have asked multiple developers I know and they think I have forgotten to "#import the .h file". But I know I have, I have tested the class in more than one file in my project. It only works in the "VNDecalLevelListViewController.h" ( which I will post its implementation if a picture). When I try and call my "initForNewDecal" method for my "VNDecalCreatorViewController.h" class in my "VNAdminViewController.h" class I received the error that this method has not been declared in "VNDecalCreatorViewController.h". But when I call it in my "VNDecalLevelListViewController.h" class it works.
I am able to allocate and use "init" to create the object and it loads with a work around I made. But I am new to programming and I can tell there is definitely a better solution.
As you will soon see as i got to allocate the VNDecalCreatorViewController in the " VNAdminViewController" the option to initialize VNDecalCreatorViewController with the proper initializer "initForNewDecal" isn't even a option.
Anyone know why this is happening ? I want to write the code right I am trying to figure out why my header file is only being read in one class.
I guess this is because you mutually imported between the two class Creator and Level. I mean you may have #include "VNDecalCreatorViewController.h" in VNDecalLevelListViewController.h and vice versa. The solution is to use #class to forward declare any classes you may need to reference instead of #import'ing the header.
Make sure that the method is declared in the header file and implemented in the .m file.
I used a tutorial that I found previously mentioned on stackoverflow, however I am running into an issue when I try to incorporate the code into a Storyboard I've created.
My storyboard is setup as follows:
Navigation Controller -> Table View Controller (static content) -> Table View Controller (where the XML should appear)
I get the following compiler error when I use the simulator and go to the Table View Controller where the XML should get output to:
unrecognized selector sent to instance 0x6b5f300
From what I gather, the problem is with the Table View Controller that I have setup. I specify its class to point to the custom viewcontroller implementation files I've created, where all of the code is from the tutorial.
I've gone through every one of the tutorial files line by line to make sure I've used them properly in my own project and they all match. I have to believe the issue is a difference between the old-style of .xib files the tutorial uses and the new style of using the storyboard to layout the app. I even made sure the tutorial code compiles and works properly in my struggle to figure out what I'm doing wrong here.
Should I be creating a different type of view controller for the XML code to be displayed on versus using the drag-n-drop table view controller object the storyboard provides?
unrecognized selector sent to instance 0x6b5f300
This means that you're sending a message to an object that doesn't understand that message. You may have forgotten to implement some method that you're calling, or you may have an object of a different type than what you expect. Occasionally, it can also mean that you've got a bad pointer, i.e. there just happens to be a new object located at the same address that was previously used for some other object.
Take a look at the object at 0x6b5f300. What type of object is it? What message are you sending to it? Answering these questions should get you a lot closer to an answer.