Whats wrong with my code?

Hi,

I'm working on a Reminder app. During the part of the code when it saves the reminder with variables I got a few errors. I don't really understand them or understand why they appear, would anyone be able to help me.




- (IBAction)MASaveReminder:(UIButton *)sender {

    [_MAReminderSaveIndicator startAnimating];
    NSString *NewReminderName = [_MANewReminderName text];
    NSString *NewReminderNameDate = [_MADatePicker date]; //Incompatible pointer types initalizing 'NSString *' with an expression of type 'NSDate * _Nullable'

    [_MAReminderSaveIndicator stopAnimating];
    if (_MANotificationSwitch (isOn) { //Called object type * _Nullable' is not a function or function pointer

        NSNumber *NewReminderNotification = @1;
    } else {
        NSNumber *NewReminderNotification = @0;
    }
}
@end

Are you talking about these lines right here?

  NSNumber *NewReminderNotification = @"1";


These won't work because the @" " literal creates an NSString, not an NSNumber. What you need to use instead is this:

  NSNumber *NewReminderNotification = @1;

'NSNumber *NewReminderNotification = @"1";'

@"1" is a string not an NSNumber.

@1 is an NSNumber.


In addition part of the point in having @property is to use the property accessors (self.property) as the only point of access to the underlying var. The exception to this is when init the instance of the class containing the properties. All of those "_MA...." should be self.MA....


Lastly naming conventions are lowercase first letter for instance properties and methods. Uppercase first letter for Classes.


For more details, see


https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html#//apple_ref/doc/uid/TP40011210-CH5-SW1


https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Conventions/Conventions.html#//apple_ref/doc/uid/TP40011210-CH10-SW1

In addition,


[_MANotificationSwitch isOn]) == @"on"


is comparing a BOOL to a string.


If _MANotificationSwitch is defined as a BOOL, just


if (_MANotificationSwitch isOn)

is adequate.

Thanks,

That wasn't the problem. But i'll change the code.

Thanks, the problem was there, but when I put in your code it came up with more errors.

Hi, don't bother answering, i took that part out of the code.

Whats wrong with my code?
 
 
Q