Xcode - The property may not be available in this context - ios

Looks like the Xcode introduces more and more new problems to developers.
Does anyone know what the hell is this issue and how to get rid of it?: The property is defined on XXX, and may not be available in this context.
The property exists in this scope and the code runs without any problems, but auto-complete is broken as always...

I resolve this issue by checking pods versions installed, upgrade or downgrade pods to access this method.
In project folder delete pods folder and reinstall it.
Check the pods versions twice which is needed to be update.

So what I'm noticing is that ever since upgrading from Xcode 12 to Xcode 13, instead of a property not displaying in auto-complete (because it is inaccessible in the current scope), it seems that Xcode 13 displays it in auto-complete with the warning/error that the property may not be available in the context. In other words, Xcode 13 seems to recognize the property exists somewhere but, in theory, shouldn't be available in the current scope
In short, I suppose this (seemingly new?) warning is basically Xcode telling you it thinks the property isn't available in the scope but can't be 100% sure, so it allows you to use it at your own risk (although usually Xcode is right and you mistakenly think it should be accessible when it isn't).

You might get that message if you're accessing a property from a header inside a framework, and the header is not added to the framework's umbrella header.
In that case, the solution is to add the header to the umbrella header.

I had a similar issue with undoActionName and redoActionName. The fix was easy - I simply added undoManager. in front. undoManager inherits from UndoManager. So, try putting the class XXX.table.

Related

Xcode won't pause at this breakpoint because it has not been resolved

Shortly after updating to Xcode 13.2.1 I started seeing some weird behaviour of breakpoints. When I run an app (in a simulator) some of my breakpoints change their look and turn to dotted blue outlined. Xcode does not stop execution at these breakpoints although code has been compiled, loaded and executed. I checked it in Console by adding some prints.
When I hover over breakpoint Xcode shows a message:
Xcode won't pause at this breakpoint because it has not been resolved
Resolving it requires that:
The line at the breakpoint is compiled.
The compiler generates debug information that is not stripped out (check the Build Settings).
The library for the breakpoint is loaded.
All trivial solutions like reloading, reapplying breakpoints have not helped.
Did anybody else see something like this? Is there a way to solve it?
Screenshot for reference:
Ok, so in my particular case rebooting laptop has helped. All breakpoints are now good. But it would still be nice to know the cause of the problem.
Make sure that the file in which you are adding breakpoint is having correct target set in target membership.
Click on .m file in which you want to add breakpoint.
Select the file inspector.
Check if you have selected correct target for that file or not (check below image).
What worked for me, was to select the files, delete them with - Delete>Move To Trash - and then drag the files back from the trash to the project.
In my case the issue was happening, because class was not added to the target, which I was trying to build.
For my case somehow the code path was never invoked and very likely considered as dead code. The same thing applies when not adding the file to the target that you want to debug.
This can be the case or somehow debugger might not be able to resolve your breakpoint. The first thing in this case should be cleaning derived data and any caches.
But instead of recloning your repo you can just delete breakpoint config from the location described in this answer
In Xcode 14 the problem is much more prevalent and "consistent". I figured out one pattern where it always fails and how to mitigate it.
If you have a final class then breakpoints set on or inside a private method will have that issue. If you remove private from the method or final from the class the breakpoints will get resolved properly.
If tried everything and nothing worked I suggest the following:
Reclone your repo
This is what worked for me.
I just passed through this problem and the solution for me was recreating the files.
Note: The ones I was trying to originally breakpoint on were copied from another project. When I created the new files, even though their Identity and Type looked just the same (target membership, encoding, paths), for some reason breakpoints started to work again.
Note 2: When copying and pasting code to your new files (if done manually), migrated breakpoints - created in the older file - will continue to fail. Only the ones created in this new file will work properly.
Hope it helps.
My case
Working on framework development. Framework is injected into the sample app for development/run purpose. Breakpoints inside the framework won't work.
Fix
Just removing xcframework in sample app and replacing with framework.
Reason
xcframework are precompiled outside of the app, so lib isn't compiled when project is built and that's why breakpoints doesn't work.
For me reboot the Xcode, and it works~

Property requires fields to be named error in objective c

I am using one third party SDK, where there are some variables declared as
I have clean and build the project and also erased the derived data, still i'm getting this error.
How to get rid off this issue?
Finally, I have found were I am wrong,
I have done a stupid thing that I installed a SDK through cocoapods
and also used the same SDK by drag and drop, so the same properties repeated twice in my code leads to this error.
Thank you for your suggestions.

Auto fix implement of missing method of protocol with Xcode?

I am not very familiar with Xcode,
Since I think every decent IDE should have a shortcut for auto-fix a template of implemented protocol (such as interface in java) to save some effects of the programmers to just fill in the logic and don't have to type in the method name and parameter stuff.
Such as when we meet this:
And I googled around and some guy said that there should be a fix all in scope thing in the Editor, but seems I can't make that clickable :-(
So, how to do this with xcode? Thanks.
Unfortunately Xcode is fairly behind compared to other IDE's in features for refactoring and such.
The main Xcode version: 8.x, can't do what you wish for. But some of it will be/is available in beta Xcode 9
Xcode may suggest a fix for a compiler error. You can click the errors individually to see the suggested fix(es) and select one.
Alternatively the 'Fix All In Scope' allows you to tell Xcode to select suggested fixes of the current file.

UIApplication.sharedApplication not available

I'm trying to get a reference to my app delegate from a UIViewController but I keep getting an this error message:
'sharedApplication()' is unavailable: Use view controller based solutions where appropriate instead.
I've been reading all the articles dealing with this kind of message but my problem seems unrelated as I'm not using any third party framework. While a Today Extension is part of my app, the class in which the error occurs is totally unrelated. I even created a completely new class and keep getting the same error:
When I do the same thing in a playground it works fine. What am I missing?
Problem solved. I've been to the Build Settings of my app again and stumbled over
Require Only AppExtension-Safe API
all set to YES. The default though is NO. When I set this to NO the error disappeared.
I sure don't remember ever touching or even knowing about this but luckily now it works.
I ran into the same error when I created and added a new target to my project (a Remote Service Notification target) and added the target definition incorrectly in my podfile.
I was following directions from a third party notification platform and they were unclear as to where to place the target definition. Initially, I added the target definition within my main target, much like the Tests target definition. This mistake led me to this error.
I ended up moving the remote service notification target definition outside of my main target to the bottom of my podfile and that resolved my problem.
In case anyone came through this error after 3 years from the question time.
Make sure that the swift file target Membership doesn't include a Today Extension.
In my case, I have not defined import Foundation in the file causing the error.
silly and late but could help an absent-minded like me. Cheers.

Xcode 7 crash every time I try to print something in the debugger console

I've searched around and can't find anything on this.
Using Swift 2 and Xcode Version 7.0.1 (7A1001). Every time I execute something in the debugger console, Xcode crashes.
The project is not very big, and has less than 10 third party frameworks.
I can't think of much more information that's relevant, but I'm sure there's more, so please do ask me if there's anything I should add to my question that would help.
I've of course cleaned build and derived data.
It's driving me insane. Thanks!
UPDATE 16/11/12
Submitted rdar://23559366.
How are you maintaining your third party frameworks? Via Carthage?
If so then this is probably your issue: https://github.com/Carthage/Carthage/issues/924
This is an issue if the location of the /Carthage/Build/iOS folder is in a different location to where it was produced (i.e if it was compiled on a different machine and the absolute file path has changed).
A temporary fix would be to run carthage build --no-use-binaries on your machine to rebuild the symbols using the current absolute file path working around the bug.
But if you wasn't using carthage then its probably not your issue so sorry
I had similar problem with Xcode whenever I hit breakpoint.
In case you see this screen right before your Xcode crashes - you are lucky and my fix might save you. All you need to do is open this window and in the Project Navigator, select any file that you want, so that instead of that white blank view you would get your code. After this you are most likely will be able to successfully stop your app at your breakpoint and perform the debug.
I am not sure why this happens, but I suspect that the reason is Debug View Hierarchy mode, which you might have triggered prior to setting you breakpoint and trying to stop at it. At least this is when it happens to me.
I have similar problem earlier.
If you try to print non-optional variable and unfortunately it holds nil value then it breaks/crash. so that make sure declare all possible variables as "Optional type".

Resources