Xcode 6 beta 2 debugger not showing variable contents after call to String.componentsSeparatedByString - swift

For some reason LLDB is not showing me the contents of variables while I am stepping through my Swift code. The actual execution works fine, but no matter what I try I can't see the contents of my strings!
Here's what I see in the variable list:
At this point type contains "name" and value contains "Logan". But you wouldn't be able to tell that looking here. If I use the "quick look" button, it says the value is "(None)".
And I get this kind of gibberish when I try to po a String from the console:
(lldb) po space
error: <REPL>:1:1: error: non-nominal type '$__lldb_context' cannot be extended
extension $__lldb_context {
^
<REPL>:11:5: error: 'Space.Type' does not have a member named '$__lldb_wrapped_expr_0'
$__lldb_injected_self.$__lldb_wrapped_expr_0(
^
However this varies. Sometimes I'll get something like:
class name = __NSAtom
or
Printing description of [0]:
(String) [0] = {
core = {
_baseAddress = Builtin.RawPointer = 0x00000001004016f0
_countAndFlags = -4611686018427387894
_owner = Some {
Some = (instance_type = Builtin.RawPointer = 0x0000000100401820 -> 0x00007fff7b3d5390 (void *)0x00007fff7b3d5340: __NSCFString)
}
}
}
or
Printing description of declaration:
(String) declaration = <DW_OP_piece for offset 8: top of stack is not a piece>
...but never the actual contents of the string!
Update:
I've noticed the problem only seems to start occurring once a call to componentsSeparatedByString() is made in the function. (This happens right at the top so as I was stepping I didn't notice that the debugger actually does show the value until this point.) So something weird is going on with that function. I've updated the question title to reflect this new information.
Interestingly, it seems once the string has been "corrupted" by this call, you can't view it anywhere else, even when passed to a different function. And any regular string variables are not viewable either. Definitely a bug, but I wonder if there's a workaround. It's getting really hard to debug my program!

When I've been encountering this, I've used either NSLog("\(myThing)") in the compiled code I want to debug, or have been calling expression NSLog("\(myThing)") while in the debugger's REPL

(note that you do not want to do NSLog("(someVariable)") as the expanded string could contain % format sequences - use NSLog("%#", "(someVariable)") or NSLog("%#", someVariable) instead)

I'd like to add an update: this problem still occurs in the latest versions of Xcode, both 6.2 release and 6.3 beta.
The problem is part of componentsSeparatedByString, and if you replace that with split everything works fine. I had four instances of this, and as soon as I changed them my app stopped crashing with a Zombie release of NSString, and all my variable names started working. I changed things like this...
let bits = value!.componentsSeparatedByString(" ")
with...
let bits = split(value!, { $0 == " "}, maxSplit: Int.max, allowEmptySlices: false)
I don't think split is nearly as readable, but at least it works!

Related

AKMIDICallbackInstrument implementation issue

Updating to the latest version of AudioKit left me changing several AKCallbackInstrument instances over to the new AKMIDICallbackInstrument class which now incorporates the former as legacy behavior. When doing so however, I ran into this weird error. Maybe a Swift nuance I am missing?
let callback = AKMIDICallbackInstrument() { status, note, velocity in
if status == .noteOn { //errors out
// do something
}
}
Comparing status to .noteOn errors out with:
"Expression type 'Bool' is ambiguous without more context.". Makes sense, because AKMIDICallbackInstrument is not returning an AKMIDIStatus in status anymore, but a straight MIDIByte (UInt8). Using direct MIDI command numerics works.
let callback = AKMIDICallbackInstrument() { status, note, velocity in
if status == 0x90 {
// do something
}
}
So we have a problem and a potential solution. I'm just not sure that this is the way to go and AKMIDICallbackInstrument didn't hit the docs yet.
For the time being, you can convert the MIDIByte to AKMIDIStatus like this:
let status = AKMIDIStatus(rawValue: Int(statusByte >> 4))
On the develop branch, there is a new initializer for AKMIDIStatus that directly takes MIDIByte as a parameter to make this a little easier.

FilterOperator bug in using quotes, same code different behavior across systems/time

this.getView().getModel().read("/QualificationProficiencySet", {
filters: [new sap.ui.model.Filter({
path: "Qobjid",
operator: sap.ui.model.FilterOperator.EQ,
value1: nQObjid
})],
success: function(data) {
that._profData = data.results;
that._oQuickView.setModel(new sap.ui.model.json.JSONModel(that._profData), "proficiencyModel");
// delay because addDependent will do a async rerendering and the actionSheet will immediately close without it.
jQuery.sap.delayedCall(200, that, function() {
that._oQuickView.openBy(oLink);
});
},
error: function(evt) {}
});
nQObjidis of type string - always.
Yesterday on our development system I saw the error
"Invalid parametertype used at function 'eq' (Position: 8)"
I noticed that the filter was appended in the URL without single quotes around the value of nQObjid. Strange because at the moment it's added as the value of the filter operator it's clearly a string. I couldn't find any related issues, but I put a (dirty) workaround in place by doing value1: "'"+nQObjid+"'".
This worked, until today, same system, didn't change the code, but suddenly the quotes are part of the value inside the gateway. So I remove the "'"again and tested, works. Then I transport the solution to production to find out that I now have the same problem on production with "Invalid parametertype used at function 'eq'.. Another user on production does not have this issue, so I'm a bit lost.
Similar issue: new SAPUI5 updat to 1.42 has odata bug "Invalid Parameters...
This may not solve your problem but it's too long for a comment, that's why I am posting it here:
When doing a read request, the framework is making a call to a helper class: V2 ODataModel.js Line #4231
aUrlParams = ODataUtils._createUrlParamsArray(mUrlParams);
The helper class then calls a private method: ODataUtils.js Line #72
return "$filter=" + this._createFilterParams(aFilters, oMetadata, oEntityType);
This private method is doing a bunch of stuff, most importantly calling another private method which is actually building the strings ODataUtils.js Line #128
sFilterParam = that._createFilterSegment(oFilter.sPath, oMetadata, oEntityType, oFilterSegment.operator, oFilterSegment.value1, oFilterSegment.value2, sFilterParam);
One of the first thing this method does is formatting your value, and I guess here is where your problem occurs: ODataUtils.js Line #393
oValue1 = this.formatValue(oValue1, sType);
The formatValue function takes your value and its Edm.Type and depending on that type does different stuff. If your objectId is a string, then it should put single quotes at the beginning and the end: ODataUtils.js Line #468
sValue = "'" + String(vValue).replace(/'/g, "''") + "'";
If the type is undefined or some weird value that UI5 doesn't know, then your value is simply cast to a String (which is probably what happens in your case).
Why is the type undefined or weird? That's where you come in... you have to do a little debugging to find out what the actual values are. If the UI5 code is unreadable you can put sap-ui-debug=true as an URL parameter:
my.sap.system.com:8000/sap/bc/ui5_ui5/sap/ztest/index.html?sap-ui-debug=true
If it's a timing issue (metadata has not been loaded for whatever reasons) then wrapping your code in a Promise might help:
var oModel = this.getView().getModel();
oModel.metadataLoaded().then(function() {
oModel.read("/QualificationProficiencySet", {
// ...
});
}

Realm object property misses its value, but I can see it when printing the whole object

I stumbled upon a weird thing when trying to fetch an object from my Realm (iOS, Swift, Realm version 0.98.2)
print("speaker:")
print(RealmProvider.appRealm.objects(FavoriteSpeaker).first!)
Correctly dumps my object in the console:
speaker:
FavoriteSpeaker {
name = Ashley Nelson-Hornstein;
}
But when I try to get the name property's value:
print("speaker name:")
print(RealmProvider.appRealm.objects(FavoriteSpeaker).first!.name)
I get an empty string 🤔
speaker name:
The four lines are together in my model's init method
Update 1: I found an answer that suggests that you merely don't see the values when printed in the Console: Realm object is missing all properties except primaryKey but I also tried displaying the name property via an alert view and that is also empty.
Update 2: Just to make sure that everything happens sequentially and on the same thread I did this:
let favorite1 = FavoriteSpeaker()
favorite1.name = "Debbie Downer"
try! RealmProvider.appRealm.write {
RealmProvider.appRealm.deleteAll()
RealmProvider.appRealm.add(favorite1)
}
print("speaker:")
print(RealmProvider.appRealm.objects(FavoriteSpeaker.self).first!)
print("speaker name:")
print(RealmProvider.appRealm.objects(FavoriteSpeaker.self).first!.name)
But the result is the same - printing name prints an empty string
The name property is probably not declared as dynamic, which leads to it reading the nil value stored on the object itself rather than reading the data from the Realm.

GWT JSONParser.parseStrict

I have been using JSONParser's parse method without many issues.
Recently, I decided to pay attention to a deprecation notice that I had been seeing. It recommended that I use either parseStrict or parseLenient.
So, I decided to try out parseStrict.
I declared a json string...
String jsonstr = "{value : [12,34],[56,78]]}";
...I confirmed that it worked with good old parse...
JSONValue jsv = JSONParser.parse(jsonstr);
...and an alert window tells me value of jsv was this:
{"value" : [12,34],[56,78]]}
Then I used parseStrict on the same string:
JSONValue jsv = JSONParser.parseStrict(jsonstr);
But my GWT app crashed with an exception!
What are the requirements in using parseStrict (vs parse)? Wny did it trip on such a simple little json string?
Uncaught exception escaped
com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses
at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:129)
......
at com.google.gwt.json.client.JSONParser.evaluate(JSONParser.java)
at com.google.gwt.json.client.JSONParser.parse(JSONParser.java:218)
at com.google.gwt.json.client.JSONParser.parseStrict(JSONParser.java:87)
In the strictest sense, the JSON you've provided just isn't strictly correct.
JSON key values should be surrounded by double quotes as described in the JSON spec, so your example JSON should be as follows:
String jsonstr = "{\"value\" : [[12,34],[56,78]]}";
Also, it appears that your braces ([]) don't match up (which I have also corrected).
In summary, it could be either the missing matching brace, or the lack of double quotes. To find out, you can wrap the offending code in a try / catch block and do as the stack trace suggests. Namely, call the getCauses method on the exception:
try {
JSONValue jsv = JSONParser.parseStrict(jsonstr);
} catch (UmbrellaException e) {
Set causes = e.getCauses();
//actually find out what the problem was
}
Note: JSONParser.parse just uses eval under the hood so be careful when using it!

; expected but <place your favourite keyword here> found

I'm trying to write a class for a scala project and I get this error in multiple places with keywords such as class, def, while.
It happens in places like this:
var continue = true
while (continue) {
[..]
}
And I'm sure the error is not there since when I isolate that code in another class it doesn't give me any error.
Could you please give me a rule of thumb for such errors? Where should I find them? are there some common syntactic errors elsewhere when this happens?
It sounds like you're using reserved keywords as variable names. "Continue", for instance, is a Java keyword.
You probably don't have parentheses or braces matched somewhere, and the compiler can't tell until it hits a structure that looks like the one you showed.
The other possibility is that Scala sometimes has trouble distinguishing between the end of a statement with a new one on the next line, and a multi-line statement. In that case, just drop the ; at the end of the first line and see if the compiler's happy. (This doesn't seem like it fits your case, as Scala should be able to tell that nothing should come after true, and that you're done assigning a variable.)
Can you let us know what this code is inside? Scala expects "expressions" i.e. things that resolve to a particular value/type. In the case of "var continue = true", this does not evaluate to a value, so it cannot be at the end of an expression (i.e. inside an if-expression or match-expression or function block).
i.e.
def foo() = {
var continue = true
while (continue) {
[..]
}
}
This is a problem, as the function block is an expression and needs to have an (ignored?) return value, i.e.
def foo() = {
var continue = true
while (continue) {
[..]
}
()
}
() => a value representing the "Unit" type.
I get this error when I forget to put an = sign after a function definition:
def function(val: String):Boolean {
// Some stuff
}