Xcode is telling me to put in expected ',' separator - xcode

xcode is telling me to put in expected ',' separator. Below is my code. even when i put in what Xcode tells me I still get an error. Does anyone know what I could be doing wrong?
} else {
if let p = placemarks?[0] {
var subThoroughfare:String = ""
if (p.throughfare != nil {
subThoroughfare = p.subThoroughfare
} // there are telling me to put this ',' here
self.addressLabel.text = "\(subThoroughfare) \(p.thoroughfare) \n \(p.subLocality) \n \(p.subAdministrativeArea) \n \(p.postalCode) \n \(p.country)"
} // xcode is telling me to put this ',' here
} // xcode is telling me to put this ',' here
})

Change this portion of your code and check if it still shows the error:
if (p.throughfare != nil) {
subThoroughfare = p.subThoroughfare
}
If it still show the error please show the if part also in your code it will help in understanding the full code as there look like extra bracket at end also

Related

Why does an error occur when I try to test if a member variable (string) in a class is empty?

I'm working on a project and need to test one of my class' member variables to verify that the user did indeed enter a string.
I've also tried using (patronName == '') and (patronName == "") but have had no luck.
Edit: Using "\n" fixes the error but the program ends without allowing the user to enter a name.
std::string Restaurant::getPatronName()
{
bool controlFlag = true;
do
{
getline(std::cin,patronName);
if ((std::cin.fail()) || (patronName == '\n'))
{
std::cout << "You must enter a name!" << std::endl;
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
else
{
controlFlag = false;
}
} while (controlFlag);
return patronName;
}
The function should read and store the name entered by the user into patronName. When trying to build, I get an error that says "no match for 'operator=='". Could this be because the object called in main is a pointer of type Restaurant?
Besides the type mismatch between the character '\n' and the std::string patronName, we can find at https://en.cppreference.com/w/cpp/string/basic_string/getline that std::getline(input, str, delim);
Extracts characters from input and appends them to str until […] the next available input character is delim, […], in which case the delimiter character is extracted from input, but is not appended to str.
So there won't be any '\n' character, if delim is the newline, in the first place.
You can use std::basic_string::empty() to check if a string is empty.
What happens with '\n' is you are comparing a string with a char, which, i suspect, there is no operator== defined for this case. If you are sure the string isn't empty, you can call operator[] formerName[0], which returns a char.
You have to write patronName == "\n" because you cannot compare string and character

OpenWhisk - character sets?

I recently started using OpenWhisk and love it.
Everything seems to work real nice, except I have run into some issue which might be related to character sets / encoding.
E.g. when I use "Scandinavian characters", like æ, ø, å, I see this in the OpenWhisk Web Editor when calling an action / trigger with payload like:
{
"station": "Rådhuset",
"no2": 8.7,
"pm10": 6.5,
"pm25": 2.2,
"time": 1461348000,
"id": "Rådhuset-1461348000"
}
I get the following result / response payload:
{
"notify": "Station R??dhuset != R���dhuset"
}
The main function in the action called looks like this:
var payload = params.payload || params;
var station = 'Rådhuset';
if (station == payload.station) {
...
} else
return whisk.done({notify : 'Station ' + station + ' != ' + payload.station});
When running the action without these characters, e.g. "Kirkeveien", everything works fine.
Has anyone else run into similar situation?!
There is a known defect with non-ASCII characters. https://github.com/openwhisk/openwhisk/issues/252
A possible workaround is to encode the string (base64 encoding for example).
try encoding:
var payload = params.payload || params;
var station = 'Rådhuset';
if (station == payload.station) {
...
} else
return whisk.done({notify : 'Station ' + encodeURIComponent(station) + ' != ' + encodeURIComponent(payload.station)});

Parsing file, ignoring comments and blank lines

As the title says, I am trying to parse a file but ignore comments (started with #) or blank lines. I have tried to make a system for this, yet it always seems to ignore that it should be ignoring comments and/or blank lines.
lines := strings.Split(d, "\n")
var output map[string]bool = make(map[string]bool)
for _, line := range lines {
if strings.HasPrefix(line, "#") != true {
output[line] = true
} else if len(line) > 0 {
output[line] = true
}
}
When run (this is part of a function), it outputs the following
This is the input ('d' variable):
Minecraft
Zerg Rush
Pokemon
# Hello
This is the output when printed ('output' variable):
map[Minecraft:true Zerg Rush:true Pokemon:true :true # Hello:true]
My issue here is that it still keeps the "" and "# Hello" values, meaning that something failed, something I haven't been able to figure out.
So, what am I doing wrong that this keeps the improper values?
len(line) > 0 will be true for the "# Hello" line, so it will get added to output.
Currently, you are adding lines that either don't start with a # or are not empty. You need to only add lines that satisfy both conditions:
if !strings.HasPrefix(line, "#") && len(line) > 0 {
output[line] = true
}

Throw error for unclosed comment block javacc

I am creating a lexer in javacc that skips block comments that start with /* and end with */. I have it working correctly for valid block comments but I am trying to figure out a way to throw an error when a block comment is unclosed...
Example:
/* this is not a valid block comment
/* this is a valid block comment*/
Here is what I have to skip valid block comments:
MORE: { <"/*"> : BLC_CMNT_ST}
<BLC_CMNT_ST> SKIP: { <"*/">: DEFAULT >
<BLC_CMNT_ST> MORE: { <~[]>}
Currently when I run the lexer a TokenMgrError is thrown when there is unclosed block comment. I would like to catch this error and/or throw my own error that displays the matchedToken.image. I have tried a few different ways but have ran into issues so any help would be greatly appreciated
How about
SKIP: { <"/*"> : BLC_CMNT_ST}
<BLC_CMNT_ST> SKIP: { "*/" : DEFAULT }
<BLC_CMNT_ST> SKIP: { < ~[] > }
<*> TOKEN : { <EOF>
{ System.out.println("Lexical state is " + curLexState ) ;
if(curLexState==BLC_CMNT_ST) throw new Error("Unmatched comment at end of file.") ; } }
I had to use SKIP instead of MORE for reasons I don't fully understand.
If you want to disallow "/*" inside of block comments you can add this production
<BLC_CMNT_ST> TOKEN: { < "/*" >
{ if(true) throw new Error("Unmatched comment at line "
+ matchedToken.beginLine
+ ", column "
+ matchedToken.beginColumn + ".") ; } }
Unfortunately this solution does not give you access to the image of the comment.

Designing Calculator in Swift - How to add single "." when require to enter floating point number?

I am developing calculator in Swift for IOS8. When pressed [0-9] button. It displays correctly. Also operator [+ - / *] works successfully.
I would need to add "." button, so user can enter floating number 19.2, 21.67, 40.6725 - How to write code so that "." appear once only, instead of 19.3.4? (not legal floating point number in calculator)
I found out rangeOfString(subString: String) might be great use. It returns an Optional. If passed String argument cannot be found in the receiver, it returns nil
#IBOutlet weak var display: UILabel!
#IBAction func appendDigit(sender: UIButton) {
let digit = sender.currentTitle!
if (digit == "․") {
if (display.text.rangeOfString("﹒") != nil) {
//DO Something Here
} else{
}
You're 99% of the way there. You only want to add the "." to your display if you don't already have one. I'd suggest looking for == nil instead
of looking for != nil.
if (digit == "․") {
if (display.text.rangeOfString(".") == nil) {
// append "." to the display text because we
// haven't see one yet
display.text = display.text + "."
} else {
// do nothing, we already have a "." in the
// display
}
You can leave off the else clause. I left it here for explanation purposes.
Vacawana's answer did't work out, as the syntax is out of date. I came up with simpler solution,
let dupDecimal = decimalDupCheck(inputDigit: digit, stringToCheck: display.text)
if userIsInTheMiddleOfTyping {
if !dupDecimal {
display.text = display.text! + digit
}
} else {
display.text = digit == "." ? "0" + digit : digit
userIsInTheMiddleOfTyping = true
}
}
func decimalDupCheck(inputDigit digit: String, stringToCheck text: String?) -> Bool {
if userIsInTheMiddleOfTyping {
return digit == "." && text?.contains(".") == true
} else {
return false
}
Basically you take in a BOOL function, checking for any duplication of ("."), and upon its result executes the next conditional brackets.

Resources