Objective-C: How do you append a string to an NSMutableString?

后端 未结 2 1204
南方客
南方客 2021-01-16 05:47

URL Download

http://code.google.com/p/mwiphonesdk/source/browse/#svn/trunk/iMADE/PrepTasks/08

I have code at the location at the

2条回答
  •  执笔经年
    2021-01-16 06:32

    As for having an NSMutableString* and needing to return an NSString*, the former is a subclass of the latter so anywhere you see an NSString* an NSMutableString* will suffice as-is.

    Your code looks OK from what you've posted. The only thing I can think of is that perhaps there isn't any data to speak of when initializing the str variable. In such a case appending an empty string will do nothing to mutableString.

    You'll also want to make sure self.mutableString has been properly allocated and initialized. You can send messages to NSObject*s that are nil which may be misleading when [self.mutableString length] returns 0.

提交回复
热议问题