I'm trying to have a textfield that determines the number of decimals an app when calculating values. the problem is its not saving my the textfield value
.h
.m
the code docent show any errors or warnings but it still docent save my values what have i done wrong
.h
Code:
#import <Foundation/Foundation.h>
@interface Preferences : NSObject
@property (weak) IBOutlet NSTextField *DecimalsField;
-(IBAction) AddDecimal:(id)sender;
-(IBAction) SubtractDecimal:(id)sender;
@end
.m
Code:
#import "Preferences.h"
@implementation Preferences
#define kDecimalsTitle @"DecimalsTitle"
@synthesize DecimalsField = _DecimalsField;
+(void) initialize
{
NSDictionary *defaults = [NSDictionary dictionaryWithObject:@"DecimalsTitle" forKey:kDecimalsTitle];
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
}
-(void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[_DecimalsField setStringValue:[[NSUserDefaults standardUserDefaults] objectForKey:kDecimalsTitle]];
}
-(void)applicationWillTerminate:(NSNotification *)aNotification
{
[[NSUserDefaults standardUserDefaults] setObject:[_DecimalsField stringValue] forKey:kDecimalsTitle];
}
- (IBAction)AddDecimal:(id)sender
{
if ([_DecimalsField.stringValue isEqualToString:@"15"]) {
return;
} else {
float result = [_DecimalsField intValue] + 1;
[_DecimalsField setIntValue:result];
}
}
- (IBAction)SubtractDecimal:(id)sender
{
if ([_DecimalsField.stringValue isEqualToString:@"0"]) {
return;
}else {
float result = [_DecimalsField intValue] - 1;
[_DecimalsField setIntValue:result];
}
}
@end
the code docent show any errors or warnings but it still docent save my values what have i done wrong