• 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
NSMutableString, NSMutableArray, scrambledString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSMutableString, NSMutableArray, scrambledString


  • Subject: NSMutableString, NSMutableArray, scrambledString
  • From: Michel Haver <email@hidden>
  • Date: Tue, 10 Jul 2001 16:25:01 +0200

Hello,

I experiment with cocoa code provided by David Remahl, but run into some
Objective C declaration problems and some NSMutableArray and NSMutableString
problems.

Let my asked my question by giving the RandomStringTester application:

RandomStringTester

Content of Controller.h file:

#import <Cocoa/Cocoa.h>

@interface Controller : NSObject
{
IBOutlet id textField;

// If I declare and initialize these NSMutableStrings in the controller.h in
the @interface Controlller I get parse errors. Why?
// Test in an other test program gives the error message string is
undeclared function, see error messages

// NSMutableString * inString = [NSMutableString
stringWithString: @"poortgriephamertitelroes"];
// NSMutableString * tempString = [NSMutableString string];

// NSMutableString * outString = [NSMutableString string];



}

- (IBAction)buttonAction:(id)sender;
@end

Content of the Controller.m file:

#import "Controller.h"
#import <Cocoa/Cocoa.h>

@implementation Controller

- (IBAction)buttonAction:(id)sender
{

// If I declare and initialiaze here, everthing works fine.
NSMutableString* inString = [NSMutableString stringWithString:
@"teststring"];
NSMutableString* tempString = [NSMutableString string];

NSMutableString* outString = [NSMutableString string];


int currentLength;
NSRange oneCharRange;

srand(time(0));


//use inString as input for tempString
tempString = inString;

currentLength = [tempString length];
while( currentLength )
{
oneCharRange = NSMakeRange(rand() % currentLength,1);

[outString appendString:[tempString
substringWithRange:oneCharRange]];
[tempString deleteCharactersInRange:oneCharRange];
currentLength--;
}

NSLog(@"Modified the strings...\n");
// NSLog(@"String in: %@.\n", inString);
// NSLog(@"String temp: %@.\n", tempString);
NSLog(@"String out: %@.\n", outString);





[textField setStringValue:outString];

}

@end

Why can't these NSMutableString declarations be placed in the Controller.h?

NSMutableString* inString = [NSMutableString stringWithString:
@"teststring"];
NSMutableString* tempString = [NSMutableString string];
NSMutableString* outString = [NSMutableString string];

What is the proper declaration if you want to place these NSMutableStrings
in the Controller.h?


I want to use an NSMutableArray to store several strings

NSMutableArray *scrambledPlayStringArray;
scrambledplayStringArray = [[ NSMutableArray alloc ] initWithCapacity: 10 ];

Then the question is how can I add for example a outString to the
scrambledPlayStringArray?

[ scrambledPlayStringArray insertString: outString atIndex: 0 ]; doesn9t
work.

If you test that you get the error message:
Jul 10 15:56:13 RandomStringTester[1338] *** -[NSCFArray
insertString:atIndex:]: selector not recognized
Jul 10 15:56:13 RandomStringTester[1338] *** -[NSCFArray
insertString:atIndex:]: selector not recognized

What is the proper selector?

Or must I use NSMutableDictionary instead?


Regards,

Michel


  • Follow-Ups:
    • Re: NSMutableString, NSMutableArray, scrambledString
      • From: Peter Ammon <email@hidden>
  • Prev by Date: getLineStart:end:contentsEnd:forRange:
  • Next by Date: Re: Getting an NSView's size
  • Previous by thread: Re: getLineStart:end:contentsEnd:forRange:
  • Next by thread: Re: NSMutableString, NSMutableArray, scrambledString
  • Index(es):
    • Date
    • Thread