• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: create NSMutableString with no limit?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: create NSMutableString with no limit?


  • Subject: Re: create NSMutableString with no limit?
  • From: Boyd Collier <email@hidden>
  • Date: Sat, 18 Mar 2006 22:35:36 -0800

I didn't say it should work or that it is reasonable to expect it to work. Rather, that it might seem reasonable. My point was to show that it doesn't work, and so, perhaps, save someone new to cocoa the trouble of finding out the hard way that it doesn't work. One runs into the same issue with NSMutableArray, where I think someone new to cocoa who read that a NSMutableArray array expands as items are added might also expect it to expand as items are inserted at an index less than the size requested.

Boyd


On Mar 18, 2006, at 6:36 PM, themacuser wrote:


On 19/03/2006, at 11:41 AM, Boyd Collier wrote:

Just a small cautionary note: the capacity you specify doesn't assure you that you can do what might seem reasonable,
or at least that's been my experience. For example,


NSMutableString *myMutableString = [NSMutableString stringWithCapacity:10];
NSLog(@" the length of myMutableString is %i", [myMutableString length]);
[ myMutableString insertString:@"this is junk" atIndex:3];

How is that reasonable? You're inserting a string into a string of length 0, at 3. That's outside the string's boundary

produces this in the Run Log:
2006-03-18 16:54:54.561 SuperSpagedi[968] the length of myMutableString is 0
2006-03-18 16:54:54.581 SuperSpagedi[968] *** -[NSCFString insertString:atIndex:]: Range or index out of bounds


But the following works

NSMutableString *myMutableString = [NSMutableString stringWithCapacity:10];
NSLog(@" the length of myMutableString is %i", [alleleString length]);
// [myMutableString insertString:@"this is junk" atIndex:3];

[myMutableString appendString:@"this is junk"];
[myMutableString insertString:@"worthless " atIndex:8];
NSLog(@"here is myMutableString %@ ", myMutableString);

However, this is within the string's boundary. The capacity of the string is being automatically extended here when there's too much on the string.




Boyd



On Mar 18, 2006, at 2:46 PM, Paul Lynch wrote:


On 18 Mar 2006, at 22:37, James W. Walker wrote:

What's the right way to create an NSMutableString with no limit on its capacity? The only initialization method listed in the docs is initWithCapacity, and it doesn't say you can pass 0 as the capacity. I can take advantage of toll-free bridging and say (NSMutableString*)CFStringCreateMutable( NULL, 0 ), but there must be a more obvious way.

Capacity is not a limit; it is a hint. So use any number you feel like. Zero might even work; I haven't tried.


I notice that there is a potential conflict in the descriptions of NSMutableString and CFStringCreateMutable in the way that capacity is described.

Paul

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40sunstroke.sdsu.edu


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >create NSMutableString with no limit? (From: "James W. Walker" <email@hidden>)
 >Re: create NSMutableString with no limit? (From: Paul Lynch <email@hidden>)
 >Re: create NSMutableString with no limit? (From: Boyd Collier <email@hidden>)
 >Re: create NSMutableString with no limit? (From: themacuser <email@hidden>)

  • Prev by Date: Re: NSPredicate with CoreData SQL store behavior
  • Next by Date: Is Core Data Daemon Safe?
  • Previous by thread: Re: create NSMutableString with no limit?
  • Next by thread: Re: create NSMutableString with no limit?
  • Index(es):
    • Date
    • Thread