How do I tell my app to read exactly what the string contains? - ios

Stumbled on an issue I can't seem to figure out. I have an app that spits out a certain amount of points depending what the string is so if someone says "not 1" then my app will show -4 points for number 1. If someone says "its 2" then the app will award 12 points for 2.
So now my issue is, If someone says "its 2" and awards 12 points which is great, exactly what I want. But when someone says "its not 2" it still awards 12 points to 2 because it contains the word "its", when I want it to show -4 points.
|| vote.lowercased().contains("its")
|| vote.lowercased().contains("its not")
I want it to be able to see if it contains exactly "its not" then it will know to -4 points.

If you want to distinguish its and its not you have to check for the longer string first
if vote.lowercased().contains("its not") {
// -4 points
} else if vote.lowercased().contains("its") {
// 12 points
}

Related

OrderClose not working in MQL4 without proper error feedback

So I have this EA that should close 2 trades together under certain conditions. Sometimes it closes only 1/2, sometimes it closes both smoothly. I cannot really pinpoint the times it closes only one and detect a pattern so I can spot the logical error.
P.S.: Obviously the trades are from different pairs running from an EA within 1 chart/pair.
The error message is this:
invalid ticket for OrderClose function
But the trade clearly exists, and i make sure I have it within the int as every time I restart the EA, if trade is already open (detected by comment) it has a message like that:
"Buy trade: [ticket number], recognised."
So I know for fact that it is recognised and within the proper int to be used. Any ideas about the error's source?
OrderClose(TicketA,LotSize,iClose(NULL,0,0),Slippage,clrGray);
OrderClose(TicketB,LotSize,iClose(SymbolB,0,0),Slippage,clrGray);
Will this fix this? I mean... it will be errored out 2/4 close orders... but I don't really care about how beautiful it looks.
OrderClose(TicketA,LotSize,Ask,Slippage,clrGray);
OrderClose(TicketB,LotSize,Bid,Slippage,clrGray);
OrderClose(TicketA,LotSize,Ask,Slippage,clrGray);
OrderClose(TicketB,LotSize,Ask,Slippage,clrGray);
Make sure that you didn't override TicketA or TicketB variable somewhere.
You can use OrderLots() function instead of using LotSize, especially when this value is changing during EA process. Additionally, by checking the OrderType(), you will avoid a mistake at the closing price.
Example:
if(yourCloseCondition){
if(OrderSelect(ticket, SELECT_BY_TICKET)){
if(OrderType() == OP_BUY){
if(OrderClose(ticket, OrderLots(), Bid, 0)){
//Print("success");
}
}
if(OrderType() == OP_SELL){
if(OrderClose(ticket, OrderLots(), Ask, 0)){
//Print("success");
}
}
}
}
Also check docs: OrderClose() and OrderType().
Update:
For different pairs running within 1 chart use close price from MarketInfo
Example:
MarketInfo("EURUSD",MODE_BID);
Check MarketInfo().

Call Directory Extension CallKit does't recognize numbers with more than 9 digits

I'm working with CallKit and developing an app with a Call Directory Extension. I've followed this tutorial and I'm currently test the capability of identify numbers that the user does't have in his contacts and show an ID from my app, but although is working perfectly with numbers of 1 to 9 digits, for example 123456, when I set numbers with 10 or more digits, iOs doesn't recognize the number. After a day and a half of google it, I've have found no information about that. If anyone can help me I'll appreciate it. Thanks in advance.
The method for set the phone numbers for recognize:
private func addAllIdentificationPhoneNumbers(to context: CXCallDirectoryExtensionContext) {
// Retrieve phone numbers to identify and their identification labels from data store. For optimal performance and memory usage when there are many phone numbers,
// consider only loading a subset of numbers at a given time and using autorelease pool(s) to release objects allocated during each batch of numbers which are loaded.
//
// Numbers must be provided in numerically ascending order.
let allPhoneNumbers: [CXCallDirectoryPhoneNumber] = [ 123456789, 1_888_555_5555 ]
let labels = [ "ID test", "Local business" ]
for (phoneNumber, label) in zip(allPhoneNumbers, labels) {
context.addIdentificationEntry(withNextSequentialPhoneNumber: phoneNumber, label: label)
}
}
With this code, when I simulate a call with the number 123456789, iOS shows the tag "ID test" and that's correct, but if I add any digit, for example 0 at the end: 1234567890, iOS does't show anything when I simulate a call. I don't know if I'm missing something.
Well, after a bunch of tests I could made it work. The point was that the phone must contain the full country code and the area code. So for example 00_52_55_4567_8932 877 or +52_55_4567_8932 both will work. But 55_4567_8932 and 4567_8932 will not work. I hope this can help someone else in the future. Thank you all!

Showing Doubles in Labels with AND without the decimal-point

To check the best answer, scroll down to Paulw11's answer.
(I apologize for any english mistakes, it's not my 1st language)
I need to solve this problem in order to continue to develop my app.
Here, I got a screenshot. (I know, it's ugly, I'm setting the constraints.)
The problem is: even when the number is a integer, it still shows as a rational. (ex.: 4 appears as 4.0, 16 as 16.0)
What I want is:
When the number in the textfield is integer, I want it to appear without the decimal-point. ( 4 appear as 4, 16 appear as 16)
When the number in the textfield is rational, I want it to appear with the decimal-point that belong to it. (4.2 appears as 4.2, 2.5 as 2.5)
What I don't want to happen:
Round any number. This will ruin the math. As I said, 4.22 needs to be 4.22 . But 4.0 needs to be only 4 .
I'll be very grateful for any help, thank you.
You can simply use the %g formatting option:
deltaValueS.text = String(format:"∆ é %g",deltaValue)
For 4.0 this will give "∆ é 4"
For 4.123 this will give "∆ é 4.123"
Do you want something like this?
let numberA: Float = 1.234
let numberB: Float = 7.000
func getStringFromNumber(number: Float) -> String {
if number - Float(Int(number)) == 0 {
return String("\(Int(number))")
} else {
return String("\(number)")
}
}
print(getStringFromNumber(numberA)) // console output: 1.234
print(getStringFromNumber(numberB)) // console output: 7

Corona SDK - iOS Game center score error, decimal comma

I'm using https://github.com/GlitchGames/GGGameCentre library to publish score and to show leaderboard window.
The problem i have is that i'm pushing a score type "4.234" and at leaderboard window, my score changes to "0.042", i don't know why.
At itunes i have a configuration type "Score Format Type=Fixed Point - To 3 Decimals" and:
For english:
Fixed Point (10,000,012.218)
And for spanish:
Fixed Point (10,000,012.218)
Please, any help?
The score must be an integer even if you set up a Fixed Point - To 3 Decimals.
If you submit 1234 you would get 1.234
To fix you problem, just multiply your score with 1000 and then submit.

IOS: Get two digits of a double (€) NOT to display the value, just return it

I´ve read a lot of posts about this but all of them were to limit the number digits to show them(NSString) .In my case I have:
I compare two double values(wich are the "same"), each of them got from different mathematical operations. For example: (4.800000 and 4.800000)
double result1=4.800000, result2=4.800000
//compare the results:
if(result1==result2){
msg.text=#"well done!!";
}else if(result1>result2){
msg.text=#"continue your work";
}
"I´m working with money (4,80€)"
In the msg label i get "continue your work" message, not the "well done". I don´t even know if the comparison is done in a correct way.
I think that the best idea would be to limit 4.800000 to 4.80 in order to delete small values and get a exact comparison.(how could i do this?)
I DONT WANT to limit the number to two digits just to PRINT the solution, I want to WORK with that number.
You can do something like this:
double a = 2.55000, b = 2.55002;
if(fabs(a-b)<1e-3) {
// code here, a == b
} else {
// code here, a != b
}
use floor(<#double#>) to round down OR just subtract them and floor the result.
For a nice answer to this problem see:
https://stackoverflow.com/a/10335601/474896
Which could be summarized as a simple as:
if (fabs(x-y) < FLT_EPSILON) {/* ... */}
However since you you're working with money values you should check out NSDecimalNumber.
Or as Marcus Zarra puts it:
"If you are dealing with currency at all, then you should be using
NSDecimalNumber.".

Resources