How to use NSLineSeparatorCharacter and NSParagraphSeparatorCharacter?

荒凉一梦 提交于 2020-01-17 05:06:12

问题


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:


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];


来源:https://stackoverflow.com/questions/3907377/how-to-use-nslineseparatorcharacter-and-nsparagraphseparatorcharacter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!