nsmutablestring

ERROR for attempting mutating immutable object

半城伤御伤魂 提交于 2019-12-12 02:28:58
问题 What is this error? I am using mutable type but still it is not working! ERROR IS : Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'mutate immutable object with deleteCharactersInRange:' NSMutableString *line= [NSMutableString stringWithString:@"here is the string"]; [line deleteCharactersInRange: NSMakeRange(1,9 )]; 回答1: My new answer: With your new code, I added one extra line at the end: NSMutableString *line= [NSMutableString stringWithString:@"here is the

How to selectively trim an NSMutableString?

可紊 提交于 2019-12-12 02:24:24
问题 I would like to know how to selectively trim an NSMutableString. For example, if my string is "MobileSafari_2011-09-10-155814_Jareds-iPhone.plist", how would I programatically trim off everything except the word "MobileSafari"? Note : Given the term programatically above, I expect the solution to work even if the word "MobileSafari" is changed to "Youtube" for example, or the word "Jared's-iPhone" is changed to "Angela's-iPhone". Any help is very much appreciated! 回答1: TESTED CODE: 100% WORKS

How to prevent appending \n to NSmutable string while parsing xml?

蓝咒 提交于 2019-12-11 12:11:28
问题 This problem is the extension of this question. Now I'm using the below code for parsing xml data, -(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { rValue = [[NSMutableString alloc]init]; isTag = FALSE; if ([elementName caseInsensitiveCompare:@"BusinessName"] == NSOrderedSame) isTag=YES; } -(void) parser:(NSXMLParser *)parser foundCharacters:(NSString *

How to return correctly a NSMutableString from a method

妖精的绣舞 提交于 2019-12-11 11:56:36
问题 I'm looking for a good way to return a string constructed by a NSMutableString avoiding leaking : eg: +(NSString *)myMethod{ NSMutableString *numberToReturn = [[NSMutableString alloc] init]; [numberToReturn appendString:@"lorem ipsum"]; return numberToReturn; } The leak instrument said I had leak with this variable. I tried autorelease but it crashes I tried to return a copy or copying the mutablestring into a nsstring but leak still present. Any idea or trick? I'have a to call this method

Clearing NSTextfield bound to a nsmutablestring

孤者浪人 提交于 2019-12-11 10:44:00
问题 I have a text field bound to a nsmutableablestring. In the action item for a button I want to clear this string but it's throwing an exception saying it's immutable. Member variable is NSMutableString* firstName; Property for binding to the text field is declared in .h @property (copy) NSMutableString* firstName; In the action for the button the following line throws an exception [firstName setString:@""]; I don't have any trouble reading the value in firstName to access what is in the text

App Crash with exc_bad_access code Exception

柔情痞子 提交于 2019-12-11 07:40:38
问题 Let me introduce my functionality of App,I use push notification & addressbook and CoreTelephony Framework. What I am doing in my application is , When i get Push notification, I save the number from the Payload in a Appdelegate Variable(Incoming_NO) , if there is no Such contact with this number , Ill create the new contact and save it. When i receive the Call , the same contact name appears as i added before , Later on I am allowing the user to Edit the Contact if he want to save the

Categories for NSMutableString and NSString causing binding confusion?

萝らか妹 提交于 2019-12-10 22:43:03
问题 I have extended both NSString and NSMutableString with some convenience methods using categories. These added methods have the same name, but have different implementations. For e.g., I have implemented the ruby "strip" function that removes space characters at the endpoints for both but for NSString it returns a new string, and for NSMutableString it uses the "deleteCharactersInRange" to strip the existing string and return it (like the ruby strip!). Here's the typical header: @interface

Implicit conversion of a non-Objective-C pointer type 'char *' to 'NSString *' is disallowed with ARC

ⅰ亾dé卋堺 提交于 2019-12-10 20:10:54
问题 For the following line of code I am getting the error below: for (UILabel *label in labels) { label.text = label.tag - 100 > someMutableString.length ? "" : "*"; } The error states: Implicit conversion of a non-Objective-C pointer type 'char *' to 'NSString *' is disallowed with ARC My variable "someMutableString" is of type NSMutableString. How do I fix in my particular case? 回答1: The problem is that your string literals are "" and "*" which are both C-style strings ( const char* ). So the

Quick way to jumble the order of an NSString?

社会主义新天地 提交于 2019-12-07 14:04:29
问题 Does anyone know of an existing way to change the order of an existing NSString or NSMutableString's characters? I have a workaround in mind anyway but it would be great if there was an existing method for it. For example, given the string @"HORSE", a method which would return @"ORSEH", @"SORHE", @"ROHES", etc? 回答1: Consider this code: .h File: @interface NSString (Scrambling) + (NSString *)scrambleString:(NSString *)toScramble; @end .m File: @implementation NSString (Scrambling) + (NSString

error : 'Attempt to mutate immutable object with appendString:' --

删除回忆录丶 提交于 2019-12-07 12:38:12
问题 I am getting an error 'Attempt to mutate immutable object with appendString:' and my code is NSMutableString *resultString= [[NSMutableString alloc]init]; for (NSMutableString *s in self.ArrayValue) { [resultString appendString:s]; NSLog(resultString); } ArrayValue is NSMutableArray. I am not able to understand where is the problem thank you in advance 回答1: As posted, the code you have will not give you the error you describe. Probably, somewhere between allocating resultString and the for