开发者

Struct in Objective c

i need to create four Struct in objective c

they are:

typedef struct FILE_TRANSFER_REQUEST_STRUCT
{
    uint8_t header[16];  // This would be MD5 of String "SymbolTalk"
    uint8_t type;        // Type of structure -> FILE_TRANSFER_REQUEST
    char    fileName[512];
    int     totalSize; //4096
    int     chunkSize; //1024
    int     numChunks; // 4
}FileTransferRequest;

typedef struct FILE_TRANSFER_RESPONSE_STRUCT
{
    uint8_t header[16];  // This would be MD5 of String "SymbolTalk"
    uint8_t type;        // Type of structure -> FILE_TRANSFER_RESPONSE
    ;
}FileTransferResponse;

typedef struct FILE_CHUNK_REQUEST_STRUCT
{
    uint8_t header[16];  // This would be MD5 of String "SymbolTalk"
    uint8_t type;        // Type of structure -> FILE_CHUNK_REQUEST

    uint8_t data[1024];
    uint8_t chunkNumber;
    uint8_t chunkSize;
}FileChunkRequest;

typedef struct FILE_CHUNK_RESPONSE_STRUCT
{
    uint8_t header[16];  // This would be MD5 of String "SymbolTalk"
    uint8_t type;        // Type of structure -> FILE_CHUNK_RESP开发者_运维技巧ONSE
    uint8_t chunkNumber;

}FileChunkResponse;

however i have no idea about Objective struct.how can i do this.where i need to create this struct(need to avoid class).is it write in objective c class file.can any one tell me how can i get this struct in another class..can any one help me...


You would do this exactly the same way as you would in plain C. Put them in one of your .h files (whichever one makes the most sense for what they are used for), outside of your @interface block. Then they will not be part of any class.

To use them in a class, just #import the .h file with your struct definition in it.


Just use like this...

typedef struct FILE_CHUNK_RESPONSE_STRUCT
{
    uint8_t header[16];  // This would be MD5 of String "SymbolTalk"
    uint8_t type;        // Type of structure -> FILE_CHUNK_RESPONSE
    uint8_t chunkNumber;

}FileChunkResponse;

@class sampleViewController;

@interface sampleAppDelegate : NSObject <UIApplicationDelegate> {
   struct FILE_CHUNK_RESPONSE_STRUCT mystructure;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@property (nonatomic, retain) IBOutlet sampleViewController *viewController;

@end

Objective-C is the superset of c it supports all c code... If you want to use C++ related classes change the file name to .mm instead of .m

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜