SWIFT 3 unexpectedly found nil while unwrapping an Optional value (works perfect in simulator) - swift3

My code works perfectly in simulator, but it pops this "fatal error: unexpectedly found nil while unwrapping an Optional value" warning when I tried to run it on my iPhone and iPad.
Strange thing is, this error didn't occur when I tried to get the value of a variable, it happened when I tried to create an object with the values I got:
"pName" and "pQuestion" are the variables with values, but as you can see, once I tried to give these value to the attributes of my object, they just became nil.
This bit of the code really behaved in the simulator, somehow it just keeps acting out on a real device.

What Swift is telling you is totally correct. Your question variable is nil when you are assigning values to it.
Don't you wanna initialise it before you start putting values into it?
I think what you are looking for is
let question = Question(name: pName, question: pQuestion)

So, I think I know whats wrong with my code.
Like Hunaid Hassan said, my current code will just get nil out of the object.
The reason my original code didn't work is because, one of the attributes is a Date variable, and because I'm in Australia, when the app runs on a real device the Date I get will be nil because I didn't set the locale.
Here's my original code:
enter image description here
And here's the fix I found to set the locale:
enter image description here
ref: https://stackoverflow.com/a/26154583/7578872

Related

LLDB cannot print local variables or access them: no member named 'table' in namespace '$__lldb_local_vars'

When attempting to print out a custom hash map variable named "table" I seem to get this error with lldb:
error: expression failed to parse:
error: <lldb wrapper prefix>:45:31: no member named 'table' in namespace '$__lldb_local_vars'
using $__lldb_local_vars::table;
~~~~~~~~~~~~~~~~~~~~^
error: <user expression 2>:1:1: use of undeclared identifier 'table'
YES the variable is declared in this scope and in fact when switching to my laptop I can use LLDB just fine and print out the table contents.
I also notice other issues when printing out a different vector. It is clearly populated when adding print statements however when using lldb to print out the vector it shows it as unpopulated and all of size 0.
I am running Fedora 35 and I have tried updating and reinstalling lldb. As I said before, my laptop is able to print everything out just fine.
I have also tried following this post:
LLDB gives "use of undeclared identifier" error for local variable
using image lookup -va $pc yields the following results indicating that the table is present:
Variable: id = {0x00018088}, name = "table", type = "HashTable &", location = DW_OP_fbreg -904, decl = main.cpp:113:24
I can share the chunk of code giving me problems but I am not sure it is relevant. I simply pass this variable into the function by reference and print it. I can print it no where else in the program.
Note:
This extends beyond printing, I cannot access the size, capacity, or anything else relating to the 'table' variable. LLDB just throws this error.
Also perhaps on an unrelated note I noticed a few weeks ago that clearly deleted objects were still showing up and printable in LLDB. I could still access the variable and manipulate the data and what not but it was very clearly deleted. Again perhaps unrelated I suspected it was just that LLDB hadn't updated the variable list or something of this nature but it cost me a bit of time figuring out why the variable wasn't deleted.
Thanks for any help in advance
EDIIT:
Compiling with clang++ seems to fix my issue on my desktop? I could just use clang instead of g++ but I still am curious how this difference in compilers changes it? I suppose I understand it fundamentally but using g++ and lldb works without issue on my laptop. Is using lldb and g++ together a big no no?
(I must use lldb on my laptop as it is an M1 and only supports lldb I believe so I just opted to use lldb on my desktop as well)

Error executing code: Wrong type of argument for conversion function

I am getting this error while Deserializing an object in AX. To make it more weird its fine in my local but failing in other.
str sampleString = conpeek(nodeData, 1);
JArray jArray = JsonConvert::DeserializeObject(sampleString );
I just had this same issue. I don't know if your issue is the same as mine, but in my case, it was coming from an attempt to grab a boolean value from a deserialized container. It would work when running from the AX client, but didn't work when running from CIL. (CLR stuff sometimes behaves differently running locally vs on the server in CIL.) Solved the issue by grabbing the value as a string, then converting to boolean.

Unable to display children:Attribute not found: value

I keep on getting this error when trying to view objects in the Debugger in PyCharm:
Unable to display children:Attribute not found: value
I have deduced that it is an error with Pycharm itself, not my code
(I get the same error on multiple scripts, but no error on with an older version of Pycharm on 2 different computers)
I'm on PyCharm Community 2017.3.4
Any ideas for workarounds, other than installing an older version?
I am finding similar issues. I too think there is something up with PyCharm it does not work as expected or previous version as you mention. I also found Pyscripter to debug as expected.
In some instances I would rely on the result object, result[0] or result.getOutput(0) to pass to next tool. Instead one can use a variable for the "output" or use the string (name) directly as input for the next tool.
For example,
facility_staging_polygons = os.path.join(outGDB, 'facility_staging_polygons\Polygon_1')
result = arcpy.MakeFeatureLayer_management(facility_staging_polygons, 'facility_staging_polygons_Layer')
# Process: Update Attributes
arcpy.AddField_management('facility_staging_polygons_Layer', "area_calc", "LONG")

c++ local variable gets overwritten (but only on some notebook)

I am facing some strange behaviour appearing only on some notebook.
I am developing in c++ using msvc 2012 and the qt framework.
I will try to sum up the problem and i am hoping that someone has any idea what the problem could be or what i could try to find out..
Generally it's the following problem:
void myclass::foo()
{
const double value1 = 100.0;
double value2;
value2 = some_function_returning_double();
if(value1 > value2)
{
//__ do something
}
}
The problem is that the condition fails as the local variable gets overwritten.
If I do some debug output i can see that variable value1 is not 100.0 anymore but some random value .. so that the comparison randomly fails ..
One thing i figured out is that everything just works fine if i don't use local variables. If i set up value1 and value2 as member variables of my class everything works without problems, but that can't be the solution.
Now the strange thing is that this error does only occur on some notebook (some mobile i5 cpu).
On my machine (i5) and on many other notebooks (even other mobile i5) everything just works fine.
I know that you won't be able to solve my problem with this little information i can offer here, but maybe some of you has any hint what the problem could be and what i could try to solve this.
Many thanks in advance.
In visual studio 2012, add a data breakpoint (debug->new breakpoint->new data breakpoint) on the address of the variable that gets overwritten.
First, break at the start of the function.
Then set the data breakpoint: just type &value1 in the "New breakpoint` the input box.
Then it should break just after the value has been modified, and you should see the culprit.
Data breakpoints are a very powerful tool, that helped me found nasty bugs very quickly.

Timed Indexed Color sets in CPN Tools that results in Unhandled Exception Error

I am using CPN Tools to model a distributed system. CPN Tools uses CPN ML an extension of SML. The project homepage is: cpntools.org
I started with a simple model and when I try to make a particular indexed color set timed, I get an "Internal error". There is another indexed colorset within my Petri-net model that is timed and works correctly. I am not sure how I can troubleshoot since I don't understand the error message. Could you help me interpret the error message or give me some hints on what I could be doing wrong?
The model is:
http://imgur.com/JUjPRHK
The declarations of the model are:
http://imgur.com/DvvpyvH
The error message is:
Internal error: Compile error when generating code. Caught error.../compiler/TopLevel/interact/evalloop.sml:296.17-296.20../compiler/TopLevel/interact/evalloop.sml:44.55../compiler/TopLevel/interact/evalloop.sml:66.19-66.27
structure CPN`TransitionID1413873858 = struct ... end (* see simulator debug info for full code *)
simglue.sml:884.12-884.43
"
Thank you~
I know this is an old question, but I run in the same problem and wasted too much time on this, so maybe it will help someone else in the future.
I didn't understand exactly the reason for this, but it seems the problem appears when you play with time values on an arch that ends to a transition (I was updating an integer value to the current time, using IntInf.toInt(time())). Now, if I move the code on the outgoing arch of that transition (that is: the one that ends in a place) there is no error.