Hi! So basically I'm working on a code that will act as a Twitter Shortener. I am taking user input, then shortening it to 140 characters using a search and replace command. I know the code might not be as pretty, or effecient as it could be, but I'm just a begginer. The problem is that I keep getting an error message:
And I have no idea how to fix it. Any tips? Here's the part of the code where the error is:
If you'd like to give any tips to actually making the code more efficient, feel free to. But I really just want to figure out this error. Thanks!!
Code:
Error: Initializer element not constant
Code:
#import "tweet.h"
#import <Foundation/NSString.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSObject.h>
#import <Foundation/NSAutoreleasePool.h>
@implementation tweet
NSMutableArray *shortWords = [NSMutableArray arrayWithObjects: @"b/c", @"4", @"2", @"2", @"sum", @"w/", @"w/o" , nil];
//error here
NSMutableArray *longWords = [NSMutableArray arrayWithObjects: @"because", @"for" , @"two", @"to", @"some", @"with", @"without" , nil];
//and here
NSMutableString *reply = [[NSMutableString alloc] init];
//and here
NSMutableString *shortTweet = [[NSMutableString alloc] init];
//and here
BOOL shorten;
-(void) shorten {
int overflow = [self length] - 140;
if([self length] > 140)
NSLog(@"Your tweet is &i characters long, %i more than 140. At this point, you can choose to shorten your tweet with the built in shortener or keep it as is.", [self length], overflow);
scanf("%@", &reply);
do{
if( reply = @"shorten" ) shorten = YES;
else if( reply = @"publish" ) shorten = NO;
else NSLog(@"Please enter either 'shorten' or 'publish' to continue");
} while (shorten != YES || NO);
if( shorten == YES ) {
[self findAndReplace];
NSLog(@"Your shortened tweet is:\n");
NSLog(@"%@", shortTweet);
}
if( shorten == NO ) {
NSLog(@"Your tweet is:\n");
NSLog(@"%@", self);
}
}
-(void) findAndReplace {
int search;
int replace;
int i;
for(i = 0; i < 7; ++i) {
search = [longWords objectAtIndex: i];
replace = [shortWords objectAtIndex: i];
[shortTweet replaceOccurrencesOfString: search
withString: replace
options: nil
range: NSMakeRange (0, [shortTweet length])];
}
}
@end
If you'd like to give any tips to actually making the code more efficient, feel free to. But I really just want to figure out this error. Thanks!!