Comparing Strings Objective C - iphone

When I use == to compare the strings it works on all but some strings that have a space added... (added with [NSString stringWithFormat:#"%# %#",self.title,collectionName])
But when I compare with isEqualToString, it returns True/YES every time. The comparison in the image goes into the condition and hits the return... Should be impossible for this to hit line 640, but it does.
Can anyone explain this?

There is a ";" after the ")" on line 637 that why it always went into the condition... damn I suck... seems like that would throw an error somehow

If you use the LLVM compiler in Debug project setting, (not quite stable enough for release yet I think), you'll get warnings about issues like the one you had.
In your case it would issue a warning than an "if" statement had an empty body.
Used in conjunction with turning on the static analyzer for every build, you can catch a ton of problems early, especially the stupid ones that are hard to debug because they are so stupid they are easy to overlook (and here I am not criticizing you, as I have made the same mistake countless times!)

Related

App is getting in infinite loop when using regular expression in loop

Something strange is happening. I'm using regular expressions that I'm 100% sure are working, but when putting them into the loop, it causes the app to get in freeze state, printing out values tens of thousands of times. Any possible suggestions?
My code :
UPDATE: IT WAS A BIG MISTAKE
As we discussed it in comments.
You have to change the incremental statement from i++ to n++
I hope that helped you.

What's wrong with brainfuck on ideone?

Clearly, there is something wrong with my understanding of brainfuck, or there's something wrong with bf interpreter on ideone.com.
By entering code as simple as ,.,. (reads two characters and prints them), I get an error "bff: out of memory (871638280)" . Why do I get this ?
NOTE: The true problem is that I'm trying to solve a problem on SPOJ, and some code that works on brainfuck interpreters that I found across the internet, doesn't work on SPOJ and ideone.com.
It appears to work fine, my BF torture test runs properly.
ideone.com 9fQ2Ej
I am NOT going to try to fight this UI to make the BF look correct!
It's here:
https://github.com/rdebath/Brainfuck/blob/master/bitwidth.b
It does appear to have a large cells size though and isn't fast enough to offset this.
EDIT: (No newlines below Grrr)
Anyway Daniel Christofani's end test:
,>+++++++++,>+++++++++++[<++++++<++++++<+>>>-]<<.>.<<-.>.>.<<.
Gives 'LA' showing that the program accepts input successfully, gives the correct character for newline and gives '-1' for end of file. As it's a big cell interpreter this is perfectly acceptable.
HOWEVER; I do see your point, there's something weird going on I suggest you try one of the javaScript implementations. They run in your browser.
http://t-monster.com/apps/brainfuck_IDE
http://www.iwriteiam.nl/Ha_bf_online.html
http://brainfuck.devbar.de/

General check of missing semicolon

As a Perl beginner I am sometimes getting compilation errors and have to search a lot to find it. In the end it is just a missing semicolon at the end of a line. Some syntax errors with missing semicolon are checked by Perl but not in general. Is there a way to get this check?
edit:
I know about Perl::Critic but can't use it atm. And I don't know if it checks for missing semicolon in general.
Because semicolons actually mean something in Perl and aren't just there for decoration, it's not possible for any tool (even the Perl interpreter itself) to know in every case whether you actually meant to leave off the semi-colon or not. Thus, there's no general-case answer to your question; you'll just need to go through your code and make sure it's correct.
As mentioned in my comments, there are various tricks you can try with your editor to expedite the process of finding potentially-incorrect lines; you must, however, either examine and fix these by hand or risk introducing new problems.
The syntax check is perl -c, but that's no different than attempting to run the program outright. Due to its flexible/undecidable syntax, one cannot generally do what you want. That's the downside of comfort and expressiveness.
Upgrade to the latest stable Perl, the parser's error messages got better/more exact over the last years and will correctly recognise many circumstances of a missing semicolon.
Rule of thumb that works for many parsers/other languages: if the error makes no sense, look a couple of lines before.
use diagnostics; usually gives you a nice hint, same as use warnings;. Try to keep a consistent coding style, check perlstyle.
Also you can use Perl::Critic online.
Also as general advice learn how to use packages and modules, try to group code into subs and study the syntax of arrays, lists and hashes. A common mistake is forgetting the ; after an anonymous hashref assignment:
my $hashref = { a => 5, b => 10};

CDT compare broken?

Help. I have been relying on the compare editor for code review, and it mostly works quite well.
But for some reason, on some files, it is giving me inconsistent results and telling me that some code is different when it is not. It can't seem to deal with commented out code in this file.
It tells me that later functions are different and tries to match lines in those functions.
I have also found cases where it simply thinks the code is different but it is not.
It then decides that there must be changes in hundreds of lines below this.
I am able to work around by remove the code with #if 0, #endif, but it is not pretty.
Has anyone else seen this and do you know of any way to fix it?
I am trying to get a clean diff do I can see just the actual changes between the files.
It is driving me to drink - and it is still early in the day!

Is it possible to define a macro that looks almost like a comment?

I try to make a useful macro for logging. But I find that NSLog and all other sort of macros that carry textual information with them simply distract a lot from the code.
Is there any way to "hack" Xcode in a way that it will interpret something like
/*** do this because of that ***/
as a macro call, which results in calling NSLog, for example? I want those logs to "feel" like comments. Anything else that looks like critical code is just distracting and reduces productivity at the end, and then there's no real benefit from logging what's going on.
Is it possible to define a macro that looks almost like a comment?
Why do you want to make your code less readable?
The answer is no, and that's a good thing.
Is there any way to "hack" Xcode in a way that it will interpret something like
/*** do this because of that ***/
as a macro call…
Probably, but that's useless. All that would do is make the syntax coloring incorrect (coloring this comment as if it were a function call). The compiler (either GCC or Clang) would still see this as the comment that it is.
Making the compiler think it's a function call or macro invocation is what would actually achieve log output at run time, but even if you could do that, it's still a bad idea because you would have a function call or macro invocation disguised as a comment.
If you want your program to log messages, write logging code:
NSLog(#"Do %# because of %#.", foo, bar);
This code is explicitly code that does something at runtime. No mystery. No surprises. That's why it's better.
You can enclose one or more lines of NSLog in curly braces and then use Xcode's folding option to hide them.
Example:
{
NSLog(#"<#label#>");
NSLog(#"<#label#>");
}
when folded look like:
{...}
The braces will also indent the statements when unfolded making them more visually distinct.
I think you should reconsider your use of log statements. If you have as many logs statements as lines of code something is wrong. You should be using the debugger to print most values and messages. If you have that many log statements you reach a point where mistakes in the log statements produce more bugs than the code. You also have a big problem cleaning up the code for release.
Not that I know of (though I may be wrong!)
I think that if you want it to look different, a macro is probably the best that you can hope for - at least it will be highlighted a different color :)