Parse issue expected expression - objective-c

I'm stumped by this error.
XCTAssertNotNil autocompleted alright and the code seems trivial.
"Parse issue" seems so strange, and there are 3 of them.
I've tried showing invisibles to find any weird spaces and stuff, but could find nothing.
I'm using Specta/Xpecta/OCMock on my other tests. Using Cocoapods
#import <XCTest/XCTest.h>
#interface SPRecipientDataViewModelTests : XCTestCase
#end
#implementation SPRecipientDataViewModelTests
- (void)testHelloNotNil {
XCTAssertNotNil(#"hello", #"hello is nil");
}

Looks like the problem here was Specta. It looks like I was using an old version of it. Updating to the latest Specta fixed this problem. Looks like there was some conflict with XCTest

Related

Expected identifier or '(' error on private instance variables

I'm using Cocos2D for the first time and trying to set up my initial scene. I just followed this tutorial http://www.raywenderlich.com/15267/how-to-make-a-platform-game-like-super-mario-brothers-part-2 and got it working perfectly. I even copied the code for the GameLayer over to use as a template for my Level0, changing the appropriate value to fit.
I'm getting an error in my private interface `Expected identifier of '(' before '{' token
#import "Level0.h"
#import "Player.h"
#interface Level0 ()
{ /// this is where I'm getting the error
CCTMXTiledMap* map;
Player* player;
CCTMXLayer* walls;
CCTMXLayer* portalWalls;
BOOL gameOver;
}
#end
#implementation Level0
....
I've coded private interfaces a million times and it even looks identical to the tutorial project. Does anyone know of reasons why this would flag an error?
The bad syntax is actually in one of those header files. You may be able to track it down by compiling the troublesome header itself rather than just including it. Comment out the #includes, then in Xcode's file inspector change the "File Type" from "Default - C header" to "Objective-C" source:
and add it to your target as a member:
Then compile. You might get some linker errors too, but you should also get this same "Expected identifier" error, now pointing somewhere near the actual site of the problem.
Don't forget to switch those settings back afterwards.

cannot combine with previous 'type-name' declaration specifier

My iOS app was working and all of a sudden I'm seeing this error: "cannot combine with previous 'type-name' declaration specifier". Any ideas on what could be causing this error?
#import "SalesAPIManager.h"
#interface SalesDelegate : NSObject { // error points to this line
__unsafe_unretained id<SalesAPIManagerDelegate> delegate_;
}
#property (unsafe_unretained, nonatomic) id<SalesAPIManagerDelegate> delegate;
- (id)initWithDelegate:(id<SalesAPIManagerDelegate>)delegate;
#end
Likewise I had a typo in a random file in the project. It was just some plain text that was accidentally placed before a comment. My suggestion to fix/find it would be to put a ; just before the statement that is flagged. This then drew a warning to the errant text when I compiled.
It's one of the disadvantages of Xcode.
Xcode is one of the worst IDE's ever, Apple is trying to make it better every update.
But this issue raises when you add "Some word" in some places that the compiler of Xcode is not looking at it.
My case was like in image :
I forgot to delete the word RESideMenu in AppDelegate.h
and the strange thing that Xcode accepts the code until the Build and when it fires error it rays it in another and not related class.
I had this same problem. It turns out I had a typo in my main.m file. Once I cleared that up, this error went away.
I saw this error when there was some dead incomplete code in my file that I'd forgotten to take out. The compiler indicated the error at the start of a method at the return type, so I spent a lot of time looking at the method declaration and call. Turned out the incorrect typo was above the method. since there was no ";" the compiler could only tell that the void keyword was misplaced.
I get the same problem. And I finally fix it after cleaning some junk text at the bottom of my .h file. you may try.
I got it in a header file when in fact the error was in the .cpp. Turns out I had a method trying to return a bool in a sketchy way:
return (x == 1 && y == 2);
Which it turns out doesn't work, but Xcode told me in this very obscure way.
Not sure if this helps, but it's another example in a seeming desert of them.
I know this is very late, however, I just had this error come up in my cpp Xcode project (line 31) and it disappeared after I completed the string initialization directly above it (line 28). My code was as follows:
Cannot combine with previous 'type-name' declaration specifier
string //STRING NEEDING INITIALIZATION
void AMPM() {
if ((firstHourChar == 1) && (secondHourChar > 2)) {
afterAM = true;
}
}

NSString may not respond to EncryptAES- Xcode Warning

It seems like I have the correct code, and it compiles, runs, and builds. BUT it does not carry out certain lines of code because of the following error: "NSString may not respond to EncryptAES"
The code where the warning occurs is contained below:
- (IBAction)Encrypt {
//Change the Input String to Data
NSData *objNSData = [NSData dataWithData:[Input dataUsingEncoding: NSUTF8StringEncoding]];
//Encrypt the Data
objNSData = [Input EncryptAES:Keyword.text]; //Line with Warning
I have searched StackOverflow for problems like this and figured that to cure this error I should use some sort of code like this in my header file:
#interface  NSString
-(NSString*)AESEncrypt:????
#end
Would this fix the warning? If so, then what do I put where the questions go?
If this code will not fix the problem then what do I do to get rid of this error and make the code function?
EDIT: I have also tried this using NSData, I get the same resulting warning
You're calling EncryptAES class method against "Input" which based on your comment and code above ([Input dataUsingEncoding...) appears to be an NSString.
NSString does not offer an EncryptAES method:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html
Checkout these SO posts:
AES Encryption for an NSString on the iPhone
uses: http://pastie.org/426530
iPhone - AES256 Encryption Using Built In Library
See here. Apparently EncryptAES is a "category" for NSData. I doubt that it will work on an NSString.

how to get rid of warning related to : indexForInsertingObject:sortedUsingBlock:

I have the following line of code:
int insertIdx = (int)[self.itemsToDisplay indexForInsertingObject:item sortedUsingBlock:^(id a, id b) {
MWFeedItem *item1 = (MWFeedItem *) a;
MWFeedItem *item2 = (MWFeedItem *) b;
return [item1.date compare:item2.date];
}];
but XCode gives me the following warning on it:
NSMutableArray' may not respond to '-indexForInsertingObject:sortedUsingBlock:
how to get rid of this warning ? and could I know where excatly this method is defined in the SDK ?
thanks so much in advance ...
-indexForInsertingObject:sortedUsingBlock: is not part of the official, public SDK. Since it looks like you haven’t declared and implemented a category on NSMutableArray that contains that method, you could write one based on this blog post by Jayway Team. Having done that, it’s just a matter of importing the header file that declares the category.
to disable the warnings for one file add this:
#pragma GCC diagnostic ignored "-Wwarning-flag"
It should ignore all warnings. The problem is however you will not see any warnings in that file. even if they are legit.

"warning: '<CLASS>'may not respond to '<[-|+]FUNCTION>'" Objective C/Xcode Compiler Warnings

I figured this one out, yet thought it worthy of its own question answer pair.
I'm new to Xcode and Objective C, and getting to know its varied eccentricities. For instance, the compiler warning "warning: ''may not respond to '<[-|+]FUNCTION>'" appears when I try to compile the following code, which all appears in my implementation file since I desire to create a private static utility function for this class:
// Here's the function declaration in the implementation file (I don't want it in the header)
+(void)authenticationRedirectTo:(NSURL *)url WithRelayState:(NSString *)relayState AndSAMLResponse:(NSString *)samlResponse {
...
}
...
// Later on, here's a call to that same function:
[CnaCalendarController authenticationredirectTo:formActionURL WithRelayState:relayState AndSAMLResponse:SAMLResponse];
...
When compiled, this produces the warning above. Next, I'll post my resolution. Feel free to contribute your ideas as well!
If what you really want is a private method, that is, you don't want the method to be in the header file, then I like to use a Category to accomplish this. I just define the category above my implementation.
// Enforce private methods by putting them in a category.
#interface YourClass (PrivateMethods)
+(void)authenticationRedirectTo:(NSURL *)url WithRelayState:(NSString *)relayState AndSAMLResponse:(NSString *)samlResponse;
#end
#implementation YourClass
+(void)authenticationRedirectTo:(NSURL *)url WithRelayState:(NSString *)relayState AndSAMLResponse:(NSString *)samlResponse {
...
}
#end
Now, it doesn't matter what the order of your methods in your implementation is which is nice so you can properly "#pragma mark"
The problem is with your method call:
[CnaCalendarController authenticationredirectTo:formActionURL WithRelayState:relayState AndSAMLResponse:SAMLResponse];
Note that the first 'r' in "authenticationredirectTo:..." is lower case, but you've declared it as "authenticationRedirectTo:...", with a capital 'R'. Given that, it's no surprise that the compiler complains that it can't find a declaration for the method you're calling. The code will likely crash on that line, too, since the method with the lower-case 'r' isn't defined.
What i think the problem is, you are declaring the function after the call to this function. And while compiling it just could not find it.
OK, here's my solution as promised:
Problem 1: Xcode will generate erroneous warnings when a function declaration or implementation appears after the call in processed source code. In my case, they are in the same file so I was able to move to function implementation above the call.
Also check the order of your imports to ensure such a function is imported before an import that calls it. I didn't see this but saw other posts where this was the case.
Problem 2: It seems Xcode has some limitations on the LENGTH of function names. Shortening my function name as shown in the snip below resolved the issue. I'll obviously pick something more meaningful.
// Here is the warning function commented out and a *shorter* name in place.
//+(void)authenticationRedirectTo:(NSURL *)url WithRelayState:(NSString *)relayState AndSAMLResponse:(NSString *)samlResponse {
+(void)X:(NSURL *)url Y:(NSString *)relayState Z:(NSString *)samlResponse {
Hope this helps you with your troubles. Don't forget to vote this answer if it is useful.