I have an object called exampleObject with two string properties: moduleName, and pool.
@property (nonatomic, assign) NSString *moduleName;
@property (nonatomic, assign) NSString *pool;
Both of these are set using two text fields named moduleNameField and poolField respectively, when an IBAction is triggered:
if (![[moduleNameField text] isEqualToString:@""]) {
[[[appDelegate moduleList] objectAtIndex:[appDelegate moduleNum]] setModulename:[moduleNameField text]];
}
if (![[poolField text] isEqualToString:@""]) {
[[[appDelegate moduleList] objectAtIndex:[appDelegate moduleNum]] setPool:[poolField text]];
}
After checking their value with an NSLog statement:
NSLog(@"The moduleName is:%@", [[[appDelegate moduleList] objectAtIndex:[appDelegate moduleNum]] moduleName]);
NSLog(@"The pool is:%@", [[[appDelegate moduleList] objectAtIndex:[appDelegate moduleNum]] pool]);
I get the correct output:
The moduleName is:Module Name One
The pool is:Pool One
Here’s where it gets weird. Upon calling a function of the exampleObject, I try to retrieve the pool and moduleName properties using:
NSString *theModName = [NSString stringWithFormat:@"%@\n", [self moduleName]];
NSLog(@"The Name is:%@",theModName);
NSString *thePool = [NSString stringWithFormat:@"%@\n", [self pool]];
NSLog(@"The Pool is:%@",thePool);
I’m able to get to the first log statement, where it prints:
The Name is:Module Name One
However, the app crashes on the nextline without an error message. What’s even more interesting is that it only crashes when thePool is a string with spaces or mixed case. If rather than “Pool One”, I had made it “poolone”, it would not crash.
Any insight into this would be much appreciated!
It sounds like a memory issue and your
NSString*properties are set to assign. I recommend setting them tocopyor at leastretainand making sure you release them in the dealloc method. Since they are set to assign messaging either one could generate a crash at anytime, it just so happens to bepoolin this case.