开发者

How to create a static NSRange?

开发者 https://www.devze.com 2023-01-23 00:23 出处:网络
It is really a stupid question, but I really don\'t know how to. I have a utility class and need to define some pre-defined variables. Here\'s how my class looks.

It is really a stupid question, but I really don't know how to. I have a utility class and need to define some pre-defined variables. Here's how my class looks.

#pragma mark File header part definiation (start offset, length)
NSRange HEADER_VERSION = NSMakeRange(0, 4); /* 0,4 */
NSRange HEADER_IDENTIFIER = NSMakeRange(4, 18); /* 4, 18*/ 
...

@interface ParserUtil : NSObject {

}

/*Parse Paper instance from file*/
+(Paper*) parsePaper:(NSURL*)file;
@end

The compiler tell me the second and the third lines are error:

init开发者_如何转开发ializer is not constant.

What is the best practice of defining the variables?


NSRange is a plain c-struct so it can be initialized the following way:

NSRange HEADER_VERSION = {0, 4};

or

NSRange HEADER_VERSION = {.location = 0, .length = 4};

See Designated inits section of gcc manual for more details

0

精彩评论

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

关注公众号