NSMutableString appendString generates SIGABRT

That makes no sense to me. Maybe someone here can explain why this is happening.

I have an NSMutableString that I use at the top of my iPhone application and then add it later. This results in a SIGABRT that does not match me. Here is the code:

Header File (Simplified):

@interface MyAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    NSMutableString *locationErrorMessage;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, copy) NSMutableString *locationErrorMessage;

@end

And the relevant parts of Main:

@implementation MyAppDelegate

@synthesize window;
@synthesize locationErrorMessage;

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    self.locationErrorMessage = [[NSMutableString alloc] init];  
}

- (void)anotherFunction {
    [self.locationErrorMessage appendString: @"Blah Blah Blah"];
}

All this seems simple enough. What am I missing?

+3
source share
3 answers

I would call it an error in creating properties, but the answer is quite simple:

(nonatomic, copy). , , locationErrorMessage , copy .

, copy NSMutableString NSMutableString, NSString ( - appendString:).

, copy retain.

( , : copy, mutableCopy, copy) = > rdar://8416047

+5

. , appendString: NSString. retain, , mutableCopy.

, [NSMutableString string] alloc-init.

+2

Btw, you have a leak there,

self.locationErrorMessage = [[NSMutableString alloc] init];

you copy the value, but you never release the actual first allocated NSMutableString.

0
source

Source: https://habr.com/ru/post/1764184/


All Articles