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.
Related
Im having an issue with the auto-generated Project-Swift.h file when I try to import it.
In the -Swift.h file:
SWIFT_CLASS("_TtC7ProjectName20InviteToComposer")
#interface InviteToComposer : NSObject <MFMessageComposeViewControllerDelegate *>
- (nonnull instancetype)initWithRecipient:(NSArray<NSString *> * _Nonnull)recipient name:(NSString * _Nonnull)name OBJC_DESIGNATED_INITIALIZER;
- (void)messageComposeViewController:(MFMessageComposeViewController * _Nonnull)controller didFinishWithResult:(MessageComposeResult)result;
#end
when attempting to compile, i get two errors from this class:
"unknown type name 'MFMessageComposeViewControllerDelegate'; did you mean 'MFMessageComposeViewController'?
and "expected a type" in regards to "(MessageComposeResult)"
I tried including #nonobjc in front of the class and function names so that it wouldn't include them in the -Swift.h file, but apparently you can't do that to a class and the function itself that has the error gives me
"Type 'InviteToComposer' does not conform to protocol 'MFMessageComposeViewControllerDelegate'" then states "protocol is not #objc but requires it."
In your -swift add #protocol MFMessageComposeViewControllerDelegate before your class declaration.
It's an apple "you probably should be using swift/we don't care enough about you to fix it" thing.
Also thing with my fix is that every time you clean the project or switch a build device, it will clear up the code and you have to add it again.
A permeant workaround is create a sub protocol of the MFMessageComposeViewControllerDelegate in objective-c and reference it from there.
Summary:
Error I'm experiencing is as title states.
I'm encountering a Reference to '' is ambiguous error. I've been unable to determine what the problem, whether if my import structure is set up incorrectly and the headers are somehow included multiple times or whatnot.
Due to request and requirements, I'm currently trying to build a single view iOS application using Objective-C and C while importing a custom pure C SDK. This is my first time using C in an iOS application, let alone including a whole SDK, so I'm not 100% sure if the process I'm doing this is correct, but have been able to resolve errors as I've been compiling.
SDK files are being included via a prefix.h which is imported into the single viewcontroller's header. I also read somewhere to use .pch instead of .h, but I'm not able to figure out how to do so given the requirements of this project...
Errors:
Reference to 'E_EXTERNAL_DEVICE_TYPE__CARD_ENTRY_DEVICE' is ambiguous.
"In file included from .../ViewController.m"
-"In file included from .../ViewController.h"
"In file included from .../prefix.h"
"Candidate found by name lookup is'_E_EXTERNAL_DEVICE_TYPE__CARD_ENTRY_DEVICE'"
"Candidate found by name lookup is'_E_EXTERNAL_DEVICE_TYPE__CARD_ENTRY_DEVICE'"
"Candidate found by name lookup is'_E_EXTERNAL_DEVICE_TYPE__CARD_ENTRY_DEVICE'"
Reference to 'E_EXTERNAL_DEVICE_CONNECT_TYPE__BLUETOOTH' is ambiguous.
"In file included from .../ViewController.m"
"In file included from .../ViewController.h"
"In file included from .../prefix.h"
"Candidate found by name lookup is'_E_EXTERNAL_DEVICE_CONNECT_TYPE__BLUETOOTH'"
"Candidate found by name lookup is'_E_EXTERNAL_DEVICE_CONNECT_TYPE__BLUETOOTH'"
"Candidate found by name lookup is'_E_EXTERNAL_DEVICE_CONNECT_TYPE__BLUETOOTH'"
Reference to 'E_EXTERNAL_DEVICE_TYPE__PRINTER' is ambiguous.
"In file included from .../ViewController.m"
"In file included from .../ViewController.h"
"In file included from .../prefix.h"
"Candidate found by name lookup is'_E_EXTERNAL_DEVICE_TYPE__PRINTER'"
"Candidate found by name lookup is'_E_EXTERNAL_DEVICE_TYPE__PRINTER'"
"Candidate found by name lookup is'_E_EXTERNAL_DEVICE_TYPE__PRINTER'"
// Device.c
...
// this and other similiar lines of code that throws the error
if((deviceType == E_EXTERNAL_DEVICE_TYPE__CARD_ENTRY_DEVICE) && E_EXTERNAL_DEVICE_CONNECT_TYPE__BLUETOOTH) {
CODE x = E_EXTERNAL_DEVICE_TYPE__PRINTER;
}
Solutions attempted
The strange part is, at one point I was able to build and run parts of the project by interatively uncommenting lines and debugging lines of code as I went along starting with SDKInitialize. But for some unknown reason, I'm now getting this error even though I've commented the SDKInitialize() in ViewController.m such that it's just an empty ViewController doing nothing.
I've also tried reverting back an older git version where the project could build fine, but it's still encountering the same error, which possibly leads me to believe this may be related to the XCode IDE or some kind of configuration settings...
cleaned project
deleted everything inside '~/Library/Developer/Xcode/DerivedData/ModuleCache/'
clean once more
build project
Already checked
Reference to 'X' is ambiguous
Reference to 'CMTime' is ambiguous
Reference to enum is ambiguous objective-c
Xcode: "Reference to NSString is ambiguous"
Build Settings
I have tried setting setting always_search_user_paths = No;
Always Search User Paths = Yes;
Header Search Paths[$(PROJECT_DIR)/.../.../.../SDK/Common] = recursive;
Header Search Paths[$(PROJECT_DIR)/.../.../.../SDK/Core] = recursive;
Header Search Paths[$(PROJECT_DIR)/.../.../.../GenericAppRoot] = non-recursive;
... etc
FYI app.xcodeproj exists inside ___/GenericAppRoot/Devices/iOS
File Structure
Common.h
//located in $(PROJECT_DIR)/.../.../.../SDK/Common
//Common.h
#ifndef __DTISDK_COMMON_H__
#define __DTISDK_COMMON_H__
//--------
// SDK Includes
//--------
//...
//--------------
// External Device Types
//--------------
typedef enum _E_EXTERNAL_DEVICE_TYPE
{
E_EXTERNAL_DEVICE_TYPE__PRINTER = 1,
E_EXTERNAL_DEVICE_TYPE__CARD_ENTRY_DEVICE = 2,
E_EXTERNAL_DEVICE_TYPE__PIN_ENTRY_DEVICE = 3,
} E_EXTERNAL_DEVICE_TYPE;
//...
typedef enum _E_EXTERNAL_DEVICE_CONNECTION_TYPE
{
E_EXTERNAL_DEVICE_CONNECT_TYPE__AUDIO = 1,
E_EXTERNAL_DEVICE_CONNECT_TYPE__BLUETOOTH = 2,
} E_EXTERNAL_DEVICE_CONNECTION_TYPE;
//...
#endif //__DTISDK_COMMON_H__
prefix.h
#ifndef prefix_h
#define prefix_h
#include "File.h"
#include "File.c"
#include "System.h"
#include "System.c"
#include "Common.h"
... etc
ViewController.h
#import <UIKit/UIKit.h>
#import "prefix.h"
#interface ViewController: UIViewController
#end
ViewController.m
#import "ViewController.h"
#interface ViewController()
#end
#implementation ViewController
- (void) viewDidLoad {
[super viewDidLoad];
// initialization callback from one of the SDK classes
SDKInitialize();
}
#end
Any additional help or insights would be much appreciated
You are including *.c files from prefix.h which is wrong. Always include only header files (*.h).
When you are including the implementation (*.c) files, the contents of the file is inserted as is, therefore you get the same definition in multiple places, leading to name collisions.
I have a header file containing an interface with properties and methods (let's call it E.h), and Xcode notifies me about syntax errors inside this header field, which make no sense because E.h doesn't contain any error.
These errors appear only under certain conditions:
E.h is already included in A.h, and there is no error.
When E.h is not included in B.m, there is no errors and it compiles fine, but if I include it in B.m, errors show up. (B.m doen't use any code from E.h)
Additional information: B.m includes B.h and then E.h .
I didn't find relevant to include source code because it represents thousands of lines and I won't ask you to analyze this.
I jus need some hints for what could be the cause and where to start searching.
Thanks in advance.
By using the "Show Preprocess" option in Xcode, I found that the property in E.h named #property (retain) NSString *MY_STRING; was replaced with #property (retain) NSString *#"My String". It appeared that there was a define MY_STRING #"My String" included in a different header file itself included in B.h, itself included in B.m before E.h .Hard to spot ! Lesson of the day : never write your variables in upper case.
In C++ this works, maybe will help you:
in file E.h
#ifndef __ECLASS__
#define __ECLASS__
<here original declarations from E.h>
#endif
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;
}
}
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.