Expression was too complex to be solved in reasonable time; - swift4.1

I have just upgraded from Xcode 8.3 to Xcode 9.4 and it kept indexing until it crashed, then it output an error.
Swift - Expression was too complex to be solved in reasonable time;
consider breaking up the expression into distinct sub-expressions
Is this a bug in Xcode 9 and Swift 4.1?
let fromString = convenience.getTimeAsString(timeStamp: timeStampDateAndTime, timeFormat: "HH:mm")
let toString = convenience.getTimeAsString(timeStamp: toTimeStamp, timeFormat: "HH:mm")
var cellData = "Booking: " + booking.BookingNumber + "\n" + "Area: " + booking.Locality + "\n" + "Postcode: " + booking.PostCode + "\n" + "Time: " + fromString + " - " + toString
How I fixed it?
var cellData = " \("Booking: ") \(booking.BookingNumber) \("\n") \("Area: ") \(booking.Locality) \("\n") \("Postcode: ") \(booking.PostCode) \("\n") \("Time: ") \(fromString) \(" - ") \(toString) "

Related

NodeJS string concatenation unusual behaviour

I am trying to construct this string for printing one message.
"At position #[" + index + "][" + _subIndex + "] TLPHN_DVC_TYP " +
+ _telNum?.TelephoneDeviceType.toString() + " ,allowed " + telephoneDeviceTypeEnum.join(',');
from watch is VsCode:
where index =0;_subIndex =0;telNum.TelephoneDeviceType =Mobile;telephoneEnum=["Mobile","Landline"];
It's returning :
At position #[0][0] TLPHN_DVC_TYP NaN ,allowed Mobile,Landline
Full Code:
if (_telNum?.TelephoneDeviceType && !(telephoneDeviceTypeEnum.indexOf(_telNum.TelephoneDeviceType) > 0)){
console.log( "At position #[" + index + "][" + _subIndex + "] TLPHN_DVC_TYP " +
+ _telNum?.TelephoneDeviceType.toString() + " ,allowed " + telephoneDeviceTypeEnum.join(','));
}
the condition should not satisfy but not sure why it's going inside the if and NaN returning. any suggestion?
It's the two plus signs: "] TLPHN_DVC_TYP " + + _telNum?// ...etc. The second one is parsed as the unary +, or a conversion to number, which obviously fails. Compare:
console.log("foo" + "bar");
console.log("foo" + + "bar");
Added #1:
if (_telNum?.TelephoneDeviceType && !(telephoneDeviceTypeEnum.indexOf(_telNum.TelephoneDeviceType) >= 0)){
console.log( "At position #[" + index + "][" + _subIndex + "] TLPHN_DVC_TYP " +_telNum?.TelephoneDeviceType.toString() + " ,allowed " + telephoneDeviceTypeEnum.join(','));
}

Can't print a number despite using str/int

I'm a noob trying to learn python 3 and I'm trying to include the half_age as a string without using directly writing the number 9 as a string but I couldn't figure it out.
I've tried:
print = str(18//2)
print = int(18//2)
print = float(18/2)
my_age = 18
half_age = (18//2)
name = "Kenny!"
greeting = "Kia Ora, "
print(greeting + name)
print("Your age is " + my_age + "and half your age is " + str(half_age ))
print("Your age is " + my_age + "and half your age is " + str(half_age ))
TypeError: can only concatenate str (not "int") to str
Try formatting all of your numbers with str ie.
my_age = 18
half_age = (18//2)
name = "Kenny!"
greeting = "Kia Ora, "
print(greeting + name)
print("Your age is " + str(my_age) + " and half your age is " + str(half_age))
Just use modern f-strings:
my_age = 18
half_age = (18//2)
name = "Kenny"
greeting = "Kia Ora"
print(f'{greeting}, {name}!')
print(f"Your age is {my_age} and half your age is {half_age}")
or
print(f"Your age is {my_age} and half your age is {my_age/2}")

How can I format this String with double x,y,total to two decimal places. output = (x + " + " + y + " = " + total);

How can I format this String with double x,y,total to two decimal places. String output = (x + " + " + y + " = " + total);
String ouput = String.format("%.2f + %.2f = %.2f",x,y,total);
System.out.println(output);
will give you the output with 2 decimal places or you can use DecimalFormat as well.

Get IP Address, Browser Type MVC 5

I need to get local system ip address and browser agent (firefox,chorme,ie,etc..) in MVC 5. Search google Request.ServerVariables["REMOTE_ADDR"] which is not working in MVC5
For getting IP Address use this code:
public static string GetIPAddress(HttpRequestBase request)
{
string ip;
try
{
ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!string.IsNullOrEmpty(ip))
{
if (ip.IndexOf(",") > 0)
{
string[] ipRange = ip.Split(',');
int le = ipRange.Length - 1;
ip = ipRange[le];
}
}
else
{
ip = request.UserHostAddress;
}
}
catch { ip = null; }
return ip;
}
https://stackoverflow.com/a/7348761/4568359
================================================================
And for getting browser info:
System.Web.HttpBrowserCapabilities browser = Request.Browser;
string brw_info = "Browser Capabilities\n"
+ "Type = " + browser.Type + "\n"
+ "Name = " + browser.Browser + "\n"
+ "Version = " + browser.Version + "\n"
+ "Major Version = " + browser.MajorVersion + "\n"
+ "Minor Version = " + browser.MinorVersion + "\n"
+ "Platform = " + browser.Platform + "\n"
+ "Is Beta = " + browser.Beta + "\n"
+ "Is Crawler = " + browser.Crawler + "\n"
+ "Is AOL = " + browser.AOL + "\n"
+ "Is Win16 = " + browser.Win16 + "\n"
+ "Is Win32 = " + browser.Win32 + "\n"
+ "Supports Frames = " + browser.Frames + "\n"
+ "Supports Tables = " + browser.Tables + "\n"
+ "Supports Cookies = " + browser.Cookies + "\n"
+ "Supports VBScript = " + browser.VBScript + "\n"
+ "Supports JavaScript = " +
browser.EcmaScriptVersion.ToString() + "\n"
+ "Supports Java Applets = " + browser.JavaApplets + "\n"
+ "Supports ActiveX Controls = " + browser.ActiveXControls
+ "\n"
+ "Supports JavaScript Version = " +
browser["JavaScriptVersion"] + "\n";
https://msdn.microsoft.com/en-us/library/3yekbd5b.aspx
To get client IP Address
var IPAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (string.IsNullOrEmpty(IPAddress))
{
IPAddress = Request.ServerVariables["REMOTE_ADDR"];
}
To get client user agent.
var userAgent = Request.UserAgent;
You are looking for something like to get Ip address
HttpRequest.UserHostAddress Property
and check out this for browser detection 51Degrees.Mobi Foundation

Which setting cause rip of format in Android Studio?

I encounter an annoying issue with Android studio. I have nicely and easy readable formatted piece of code:
But if I press Code - reformat code, my string declaration turns in complete mess:
It would not be a problem if only new line characters were removed, but Code - reformat code also split my strings and make empty line insertions (WTF)
Compare string before reformat:
private static final String
DATABASE_CREATE =
"create table "
+ TABLE_NAME + "("
+ COLUMN_ID + " integer primary key autoincrement, "
+ COLUMN_ITEM_ID + " integer default '0', "
+ COLUMN_SLUG + " text default '',"
+ COLUMN_TITLE + " text default '',"
+ COLUMN_TYPE + " integer default '0', "
+ COLUMN_YOUTUBE_ID + " text default '',"
+ COLUMN_ARTISTS + " text default '',"
+ COLUMN_ARTISTS_SLUG + " text default '',"
+ COLUMN_DESCRIPTION + " text default '',"
+ COLUMN_PICTURE + " text default '',"
+ COLUMN_SOURCE + " text default '',"
+ COLUMN_VIEW_COUNT + " integer '0',"
+ COLUMN_GOOGLE_LINK + " text default '',"
+ COLUMN_OFFLINE_SOURCE + " text default '',"
+ COLUMN_IS_SAVED_OFFLINE + " integer '0', "
+ COLUMN_OFFLINE_PLAYS + " integer default '0',"
+ COLUMN_DOWNLOADING_ID + " integer default '-1',"
+ COLUMN_IS_LIKE + " integer default '0' " +
");";
and string after reformat:
private static final String
DATABASE_CREATE =
"create table " + TABLE_NAME + "(" + COLUMN_ID + " integer primary key autoincrement, " +
"" + COLUMN_ITEM_ID + " integer default '0', " + COLUMN_SLUG + " text " +
"default ''," + COLUMN_TITLE + " text default ''," + COLUMN_TYPE + " integer " +
"default '0', " + COLUMN_YOUTUBE_ID + " text default ''," +
"" + COLUMN_ARTISTS + " text default ''," + COLUMN_ARTISTS_SLUG + " text " +
"default ''," + COLUMN_DESCRIPTION + " text default ''," +
"" + COLUMN_PICTURE + " text default ''," + COLUMN_SOURCE + " text default " +
"''," + COLUMN_VIEW_COUNT + " integer '0'," + COLUMN_GOOGLE_LINK + " text " +
"default ''," + COLUMN_OFFLINE_SOURCE + " text default ''," +
"" + COLUMN_IS_SAVED_OFFLINE + " integer '0', " + COLUMN_OFFLINE_PLAYS + " " +
"integer default '0'," + COLUMN_DOWNLOADING_ID + " integer default '-1'," +
"" + COLUMN_IS_LIKE + " integer default '0' " +
");";
You clearly can see lots of "" which were not present before.
How to fix such strange behaviour?

Resources