Cannot see Swift variable contents using AppCode - swift

I'm using Appcode-EAP 3.2, but I've also tried this with Appcode 3.1.7.
When stopped in the debugger, I can see the local variables,
e.g.
fromJSON = []
self = []
However, if I move one of these to the Watches window to examine its contents, I get this:
self = Cannot evaluate expression for language Swift
I can't believe it isn't possible to see the values of a variable or property. Can anyone guide me as to what I'm failing to do?

Current AppCode versions (stable 3.1 and 3.2 EAP) don't support Swift debugging. It should be included into the final 3.2 release however: https://youtrack.jetbrains.com/issue/OC-11626

Related

#available fails to prevent calls to functions in swift

I am using #available to prevent some functions to be called at certain OS versions. Lets say I have two functions and both should be restricted to macOS version 12 and below. Not available at macOS 13. Hence I want to write
#available(macOS, obsoleted: 12)
extension MyStruct {
func myFunc1() -> String { ... }
func myFunc2() {
let resultOfCallOfMyFunc1 = myFunc1()
}
}
I thought that this way both functions are only available at the same platfroms. But I am getting error, when I try to use myFunc1 in myFunc2 why is that?
The error is: "myFunc1()" is unavailable in macOS
I also tried to mark each function separately instead of marking the whole extension, but no luck there either.
Any reason why this fails? How to use #available the way, that I will be able to use one function inside another one?
According to the Language Reference, obsoleted indicates the first version in which the member is unavailable.
The obsoleted argument indicates the first version of the specified platform or language in which the declaration was obsoleted.
So you should write obsoleted: 13 instead. obsolete: 12 would mean that the extension is obsolete since macOS 12. Assuming that your minimum deployment target is equal to or higher than macOS 12, this would mean that the extension is obsolete on all the possible devices your app will be installed on, hence "myFunc1 is unavailable".
Note that the obsolete argument prevents code that targets higher OS versions from compiling. It is still possible to compile code targeting a lower version, and run myFunc1 on macOS 13+. If you don't want myFunc1 to execute at all on macOS 13+ at all. You should use an #unavailable check:
if #unavailable(macOS 13, *) {
let resultOfCallOfMyFunc1 = myFunc1()
}

Xcode code console printing blank when using po

When I use the terminal/console to print out a value by typing po object it prints blank for all objects. This only happens for my work project which is really big and my small demo projects work fine.
Also its not happening for any of my colleagues. I was using Xcode 10.2 and upgraded to Xcode 10.3 to see if it fixes the problem.
stringValue is an extension on bool that returns "true" or "false" however this happens for all objects so I don't think the code there is relevant.
Due to the huge compile time of our app its quite time consuming to always write print(object) or debugPrint(object) in the code.
Any ideas how to fix the issue?
Can you try to press on i it does the same, but sometimes it's work for me.
Also check this out: XCode's po command has stopped working
Let me know if this help you.
Try the v command.
From the XCode release notes
The LLDB debugger has a new command alias, v, for the “frame variable”
command to print variables in the current stack frame. Because it
bypasses the expression evaluator, v can be a lot faster and should be
preferred over p or po. (40066460)

Swift Boolean value <invalid>

The attached screen shot says it all: I have a valid true Bool, I negate it with the bang operator, and (Xcode tells me) I have an invalid value.
It appears that this "invalid" value does behave as if it were false. But really, wtf?
I've had this issue in Xcode 8.3.1 and Swift 3.1 https://github.com/onmyway133/notes/issues/278
I tried
Clean build folder and delete derived data folder
Delete the app
Reset simulator
Restart Xcode
Restart Mac
But does not work. The workaround is to
let enabled = disable ? false : true
I'm no LLVM expert but I wouldn't be surprised about this behavior at all, unless optimization is set to Onone in which case it should have left your code alone. The intermediate variable is just asking to be optimized away, after all.
Got the same issue, with correct value for add code like print(theBoolValue).
But when use p in swift command line. Or just check the value in debug stack, the value become <invalid>(Oxfe).

Set collection type swift

I am learning swift through Apple's documentation and I am on the Collection Types chapter and in the Sets section.
One of the examples is this
var letters = Set<Character>()
but when I go to enter that I get this following error.
error: use of unresolved identifier 'Set'
var letters = Set<Character>()
there was a revision on sets according to their documentation, but nothing is helping me there.
Native Set is available since Swift 1.2. Everthing points that you're using a lower version.
Swift 1.2 and Xcode 6.3 beta
New native Set data structure — An unordered collection of unique elements that bridges with NSSet and provides value semantics like Array and Dictionary.

Testing for weak-linked symbol in iOS does not work as expected

I am running into a weird issue when trying to test for the existence of a symbol that is introduced in a newer version of the OS. I follow the Apple guidelines on using weak-linked symbols, i.e.
Check the availability of an external (extern) constant or a
notification name by explicitly comparing its address—and not the
symbol’s bare name—to NULL or nil.
To reproduce the issue, I am using the latest iOS 6 SDK on the latest Xcode 4.5.2, using the default compiler (Apple LLVM compiler 4.1). I weak-linked the Social framework (which is only available on iOS 6+). And I run this code on iOS 5.1 (the deployment target is lower than 6):
NSLog(#"%p", &SLServiceTypeFacebook);
if (&SLServiceTypeFacebook)
NSLog(#"Yes1");
if (&SLServiceTypeFacebook != NULL)
NSLog(#"Yes2");
The output is:
0x0
Yes1
Yes2
In other words, we can verify at runtime that the expression &SLServiceTypeFacebook evaluates to the value 0. Yet, if statements that test on this expression treat it as if it is true.
Update:
From this question, I found that this workaround works with no optimization, but not with optimization:
typeof(&SLServiceTypeFacebook) foo = &SLServiceTypeFacebook;
if (foo)
NSLog(#"Yes3"); // does not get executed on -O0, but does on any optimization
Update:
It appears that this problem does not exist with UIKit symbols. Running the following on iOS 4.3:
NSLog(#"%p", &UIKeyboardDidChangeFrameNotification);
if (&SLServiceTypeFacebook)
NSLog(#"Yes1");
if (&SLServiceTypeFacebook != NULL)
NSLog(#"Yes2");
The output is:
0x0
I hypothesize that the difference is that the UIKit symbol has a NS_AVAILABLE_IOS() macro next to it, so somehow the compiler handles it correctly. In the case of the Social framework symbol, it doesn't have a NS_AVAILABLE_IOS() macro since the entire Social framework itself is only available since iOS 6 (i.e. the symbol is available since the version of the framework, so I guess the don't need this macro?); but then the compiler does not handle the symbol correctly.
Are you sure you don't want to check that the SLRequest class exists instead of checking for this constant?
In any case, the issue is that the compiler is optimizing the test away (it interprets this as testing a constant expression which is true at compile time). You can circumvent this by reading this address into a local volatile variable. Or you could dynamically search for the symbol at runtime.
But I would consider just checking for the SLRequest class instead.
Here are at least these three options:
#include <dlfcn.h>
NSString* const * volatile check = &SLServiceTypeFacebook;
if (check != NULL)
NSLog(#"SLServiceTypeFacebook is defined");
// Another approach would be to call dlsym() at runtime
// to search for this symbol:
if (dlsym(RTLD_DEFAULT, "SLServiceTypeFacebook"))
NSLog(#"SLServiceTypeFacebook found via dlsym");
// But if you really just wanted to know is if SLRequest
// is available, you should really just do this:
if ([SLRequest class])
NSLog(#"SLRequest class is available");
Any of these should work as you were expecting in iOS5.1 versus iOS6.
just check with NSClassFromString if you can get the classes.. objC is all classes anyway :D