Finding curCapacity and maxCapacity Value, iPhone - objective-c

A method which can be used for finding the battery percentage of your device is found here:
http://blog.coriolis.ch/2009/02/14/reading-the-battery-level-programmatically/comment-page-1/#comment-6085
I have tried it and it works great. If you have a closer look at the code there are two values curCapacity and maxCapacity. I want to be able to use these values in other calculations, yet when I try and do this I always get the error 'undeclared'.
Any ideas as to why?

where are you trying to use this variables? they are declared inside - (double) batteryLevel method so you cannot use them in other methods. if you want to use them in other places, declare them in your .h file. so you will be able to get access to these values not only from this method.

Related

Converting std::int to System::Single

Apologies if there's an answer out there already; but all I seem to be getting is a bunch of "I want to turn my 1 into a 1.0" chaff from my Google searches.
First things first. No, I'm not talking about a simple Convert::ToSingle() call. Rather, I need to convert the representation of the data to a System::Single.
So in other words, I'd like to take int myInt = 1065353216;, and the result should be something like 1.000. I know the pure c++ method would be something like float myFloat=*(float *)&myInt;;but I need the managed version.
Thanks in advance for your help.
If you're in C++/CLI, you can do it the same way as you do in C++: float myFloat=*(float*)&myInt;
In pure managed-land, there are built-in methods to do this for double & Int64 (DoubleToInt64Bits and Int64BitsToDouble, but not for single & Int32. However, if you look at the implementation of those methods (MS Reference Source), you'll see that they're doing the exact same thing as you have listed, so that's also the managed way to do it. The only difference is if you do it in C#, you have to tag the method as unsafe.

Get the Objective function value in SCIP

I am solving an Integer program model with SCIP and I need to store the objective function value. I was wondering how I can get the objective function value after solving the IP model? can someone help me?
You can use SCIPgetPrimalbound() to get the best solution value.
Also, in the interactive shell the column "primalbound" will show the current best solution value and after the optimization process stops the primlalbound is also stated.
(Note, you might want to check whether a solution was found.)
If your problem is infeasible it 10^20 (SCIPs infinity value) is printed.
(If you want to see the objective function value and the solution values of each variable, you can enter display solution in the interactive shell, which will show all non-zeros solution values and the objective function value.)
See also http://scip.zib.de/doc/html/SHELL.php .

ios - Compare values of an array at runtime, not knowing what they are going to be

I have 2 places where I require a UIPickerView in my app and the values that the second represents is dependent on the result of the first one.
However the values of the first one can be changed at run time and so I do not know what they are going to be. This leaves me out the hardcoding option of doing it this way:
if([_menuCategoryPickerFld.text isEqualToString:#"food_breakfast"])
{
}
This would require hardcoding values into my app.
Now the source of my data is MySQL imported via JSON, so when I select an option in the first UIPickerView, it will query and return the correct JSON file.
I need to know if I can compare a value of an array that I will only receive once the app is running??
Thanks in advance.
Not sure I understand, but why not just:
NSString* mystery = #"blah";
if([_menuCategoryPickerFld.text isEqualToString:mystery]){ ... }
You don't need to the the contents of a string to use it in a compare this way.

Something really dumb with return values

I'm doing something really dumb, and I don't see it.
I've got an object doc with a method:
-(float) currentOrient
{
return 50.5;
}
In another object, I call:
-(void) showPage
{
float rot2=0;
rot2 = [doc currentOrient] ;
NSLog(#"SP rotation is %.2f", rot2);
}
However, the output is :
SP rotation is 1112145920.000000
No, one question is "Why is the %2f not formatting correctly?" But the more confusing question is "Where is that number coming from?" Yes, I've walked through it with a debugger, the value of rot DOES change from the garbage it starts with. and that number DOES appear to be consistent.
Clearly something really dumb is going on...
It sounds like the showPage method doesn't know right return type for currentOrient, so it's interpreting the value returned as an int and casting that nonsensical int to a float. Are you getting any warnings? Are you sure you're importing the header for currentOrient correctly? Is the currentOrient method declared correctly?
I can answer the first question:
Why is the %2f not formatting correctly?
Because it ought to be %1.2f to round to two decimal places (which I believe is what you're trying to achieve?)
And guess at the second:
Do you have a property named rot in the code? Other than that... shrug... I don't know - I'm assuming you've simplified the example to post on SO, have you taken out other code that may be relevant? Based on the information you've provided everything should be ducky.
On a side note: When I hit bugs like this I go do something physical. Usually when I come back my head is clear and I find the problem immediately. You might want to give that a try too! :D

Compare the value of a variable at intervals

Hey I have a problem comparing the value of a CGPoint (struct with two ints: x and y) with another at certain time intervals.
One is called location and has the value of where the cursor is. Every half a second or so, I want to see if it changed. How do I do this? The language is Objective-C (so C++/C stuff should work)
What are you trying to do with this? Would it make more sense to use Key Value Observing to observe when one or both values change?
Take a look at the NSTimer documentation. It does what you want.
As noted in the CGGeometry docs, Apple provides a function, CGPointEqualToPoint(), for doing just this. You would have a CGPoint variable that stores the old value and compare it to the new value you get.