所以我最近开始学习Objective-C,在工作中我们一直在开发一个Android应用程序,我们稍后也会在IOS上发布,所以我试图了解如何重新编写一些将代码转换为 Objective-C 让我们以此为例:
import java.io.Serializable;
/*
* Serializable is needed for sending in Android intents.
*/
public interface IMessage extends Serializable {
enum MessageID {
// Nothing to send or reply
NONE,
// Client polls server
POLL,
POLL_OK,
// Client internal, indicates network problems
NONETWORK,
// Indicates programming errors
INVALIDMESSAGE,
INVALIDSTATE,
UNKNOWNMESSAGE,
// Application setup messages
LOGIN,
LOGIN_OK,
LOGIN_ACCOUNT_DOES_NOT_EXIST,
LOGOUT,
LOGOUT_OK,
REGISTER,
REGISTER_OK,
REGISTER_NICKNAME_ALREADY_EXISTS,
UPDATEACCOUNT,
UPDATEACCOUNT_OK,
UPDATEACCOUNT_NICKNAME_ALREADY_EXISTS,
// Game setup messages
QUERYGAMESTATUS,
QUERYGAMESTATUS_IDLE,
QUERYGAMESTATUS_PENDING,
QUERYGAMESTATUS_PLAYING,
REQUESTGAME,
REQUESTGAME_OK,
REQUESTGAME_ALREADY_IN_GAME,
REQUESTGAME_DUPLICATE_REQUEST,
ENTERGAME,
ENTERGAME_OK,
ENTERGAME_ERROR,
// Game playing messages
// ...
};
MessageID getID();
String encodeAttributes();
void decodeAttributes(String data);
}
所以我想知道您是否必须始终将 .m 文件与 .h 文件一起使用,因为我猜在 Obejctive-C 中可能会是这样的:
@interface IMessage : NSObject
typedef enum {
//all the same
} MessageID;
NSString *encodeAttributes();
-(void) decodeAttributes(NSString data);
还是我必须将它分成两个文件?因为我猜你必须同时拥有一个 .m/.h 文件?