How to use NSLineSeparatorCharacter and NSParagrap

2019-08-19 02:34发布

I wonder how I can use the constants NSLineSeparatorCharacter and NSParagraphSeparatorCharacter as a parameter to a function instead of hard coding \n.

- (id)initWithSeparator:(id)separator {
 m_separator = separator;
}

What would be the correct parameter type and what conversion needs to be done?
Depending on the file contents I wish to call the function like ...

Object* obj = [[Object alloc] initWithSeparator:NSLineSeparatorCharacter];

... or ...

Object* obj = [[Object alloc] initWithSeparator:NSParagraphSeparatorCharacter];

Apples String Programming Guide / Paragraphs and Line Breaks was not helpful, though.

1条回答
看我几分像从前
2楼-- · 2019-08-19 03:11

The correct parameter type would be unichar - no need to convert anything? If you want to create an NSString later, you'll have to use something like

    unichar myChar = NSParagraphSeparatorCharacter;
    NSString *myString = [NSString stringWithCharacters:&myChar length:1];
查看更多
登录 后发表回答