objective c - Obj-C enum "Incompatible Types in initialization" -
I seem to be having problems with enum type initialization which seems simple to solve, but I do not know that How do it Suppose I declare the following enum type:
typed numeric nxsound type {nxsandtipone, nxsandtypefant, nxsandtapbackgroundmuse}} nxsound type; I declare a feature method to return an NSSToundType enum type, as if it is an NSString object (note: NXSound is an object that has a NXSoundType attribute called "Type"): - (NXSoundType) nxSoundTypeFromIdentifier: (NSString *) nxSoundIdentifier {NXSoundType type = NXSoundTypeNone; (Self.nxSounds in NXSound * nxSound) {if ([nxSound.identifier isEqualToString: nxSoundIdentifier]) {type = nxSound.Type; }} Return type; }
So far, so well. But the following call is not working:
NXSoundType type = [self nxSoundTypeFromIdentifier: @ "kNXTargetGameSoundIfEffectTic"];
What's wrong? Thank you in advance.
I resolved the problem. Despite the compiler error message, this problem was not related to the incorrect enum type declaration / initialization. The problem was that
- (NXSoundType) nxSoundTypeFromIdentifier: (NSString *) nxSoundIdentifier;
was defined as a personal law in the base-class and it was called by the sub-class. In this way, due to the obj-C dynamic nature, expected to return id
, which can not be assigned to NXSoundType
enum (objects only). A simple artist removed the problem, the solution method was used to change the call:
NXSoundType type = (NXSoundType) [self nxSoundTypeFromIdentifier: @ "kNXTargetGameSoundIfEffectTic"];
All the answers are appreciated and sorry for any confusion. Hope this helps someone.
Comments
Post a Comment