EventKit Reminders - eventkit

I am pulling my hair out trying to learn the basics of EventKit reminders. I am trying to recreate the tutorial here: http://www.techotopia.com/index.php/Using_iOS_6_Event_Kit_to_Create_Date_and_Location_Based_Reminders
But when I try to build the project I get errors in my .m file of "missing context for method declaration"
both at the IBAction and at the CreateReminder. I tried to look here for advice but still can't seem to figure out what I am doing wrong. Have to say what are the use of these tutorials if they are all the time leaving out some basic information that prevents it from building. If anyone can help, I would greatly appreciate it.
#import <UIKit/UIKit.h>
#import <EventKit/EventKit.h>
#interface ReminderAppFirstViewController : UIViewController
#property (strong, nonatomic) EKEventStore *eventStore;
#property (strong, nonatomic) IBOutlet UIDatePicker *myDatePicker;
#property (strong, nonatomic) IBOutlet UITextField *reminderText;
- (IBAction)setReminder:(id)sender;
- (void)createReminder;
#end
- (IBAction)setReminder:(id)sender {
if (_eventStore == nil)
{
_eventStore = [[EKEventStore alloc]init];
[_eventStore requestAccessToEntityType:EKEntityTypeReminder comnpletion: ^(BOOL granted, NSError *error) ] {
if (!granted)
NSLog(#"Access to store not granted");
}];
}
if (_eventStore != nil)
[self createReminder];
}
- (void)createReminder
{
EKReminder *reminder = [EKReminder
reminderWithEventStore:self.eventStore];
reminder.title = _reminderText.text;
reminder.calendar = [_eventStore defaultCalendarForNewReminders];
NSDate *date = [_myDatePicker date];
EKAlarm *alarm = [EKAlarm alarmWithAbsoluteDate:date];
[reminder addAlarm:alarm];
NSError *error = nil;
[_eventStore saveReminder:reminder commit:YES error:&error];
if (error)
NSLog(#"error = %#", error);
}

The part below looks like it should be in the .h file, not the .m. Properties declared in the #interface section of the .m are essentially private and only accessible within the .m. The methods are also out of place. Perhaps a mistake in the tutorial.
#import <UIKit/UIKit.h>
#import <EventKit/EventKit.h>
#interface ReminderAppFirstViewController : UIViewController
#property (strong, nonatomic) EKEventStore *eventStore;
#property (strong, nonatomic) IBOutlet UIDatePicker *myDatePicker;
#property (strong, nonatomic) IBOutlet UITextField *reminderText;
- (IBAction)setReminder:(id)sender;
- (void)createReminder;
#end

Related

Objective-c: AppDelegate NSString

I have an NSString that as an instance variable within my appdelegate as below:
distributedLCAAppDelegate.h:
#class distributedLCAViewController;
#interface distributedLCAAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
distributedLCAViewController *viewController;
NSString *token;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet distributedLCAViewController *viewController;
#property (nonatomic, copy) NSString *token;
#end
section from distributedLCAAppDelegate.m:
#implementation distributedLCAAppDelegate
#synthesize window;
#synthesize viewController;
#synthesize token;
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
token = [NSString stringWithFormat:#"%#",deviceToken];
token = [token stringByReplacingOccurrencesOfString:#" " withString:#""];
token = [token substringWithRange:NSMakeRange(1, [token length]-2)];
}
I need to be able to use this token variable within the view controller. Currently this is what I have:
section from within distributedLCAViewController.m:
- (IBAction)switchWasActivated:(id)sender
{
NSString *token2 = [[[distributedLCAAppDelegate alloc] token] autorelease];
}
However, token2 = "invalid cfstringref".
I initially tried declaring a public method called getToken, which just returned token. But I was getting the same problem in that case as well.
Any help would be appreciated!
Try this : (UPDATED) (fixed)
NSString* token2 = ((distributedLCAAppDelegate*)[[UIApplication sharedApplication] delegate]).token;
Try following -
- (IBAction)switchWasActivated:(id)sender {
distributedLCAAppDelegate *delegate = (distributedLCAAppDelegate *) [[UIApplication sharedApplication] delegate];
NSString *token2 = delegate.token;
}
Can you check the Files' Owner in "MainWindow.xib" if its delegate outlet is set to your distributedLCAAppDelegate? Just Ctrl-click on the yellow box-icon in Interface Builder.
distributedLCAAppDelegate* delegateobj = [(distributedLCAAppDelegate*)[UIApplication sharedApplication] delegate];
NSString *token_ = delegateobj.token;
NSLog(#"token_ :%#",token_);
Try This , it should work

IOS5 -[__NSCFDictionary nombre]: unrecognized selector sent to instance 0x6da25a0

I get an error when trying to access an attribute of a class "event"
Json List all Ok When I trying to access the error jumps
Evento* bean = [ListaEventos objectAtIndex:indexPath.row];
DetalleViewController *detalle = [self.storyboard instantiateViewControllerWithIdentifier:#"Detalle"];
NSLog(#"detalle: %#",[bean nombre]);//bean Log OK!!, but bean.nombre Error!! why?
The class: evento.h
#interface Evento : NSObject
#property (strong, nonatomic) NSString *idevento;
#property (strong, nonatomic) NSString *nombre;
#property (strong, nonatomic) NSString *descripcion;
#property (strong, nonatomic) NSString *fecha;
#property (strong, nonatomic) NSString *telefono;
#property (strong, nonatomic) NSString *direccion;
#end
Evento.m
#implementation Evento
#synthesize idevento;
#synthesize nombre;
#synthesize descripcion;
#synthesize fecha;
#synthesize telefono;
#synthesize direccion;
#end
What you get out of [ListaEventos objectAtIndex:indexPath.row]; is of kind NSDictionary and not of kind Evento as supposed. Check your data!
The object you get with
[ListaEventos objectAtIndex:indexPath.row];
Is of type dictionary which doesn't have the method or the property nombre.
If you could add also add here the json we can help you to get the correct evento object.

NSCFNumber unrecognized selector

i want to send data between views, but i get an error: unrecognized selector....
and the in the debugger, the variable mystring is a NSCFNumber ("at this time") instead of NSString...
allergy_appAppDelegate.h
#import <UIKit/UIKit.h>
#interface allergy_appAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
NSMutableArray *result_array;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
#property (copy , readwrite) NSMutableArray *result_array;
#end
viewcontroller.m
allergy_appAppDelegate *dataCenter = (allergy_appAppDelegate *)[[UIApplication sharedApplication]delegate];
dataCenter.result_array = [[NSMutableArray alloc] initWithArray:Parser_result];
result.m
allergy_appAppDelegate *dataCenter = (allergy_appAppDelegate*)[[UIApplication sharedApplication]delegate];
show_user_array = [[NSMutableArray alloc] initWithArray: dataCenter.result_array]
for (NSString *mystring in show_user_array) {
textView.text = [[textView text] stringByAppendingString:#"\n"];
textView.text = [[textView text] stringByAppendingString:mystring];
}
Instance variables should be camel-cased, not have _. I.e. result_array should be resultArray. Classes start with capital letters.
Are you sure your result array is full of instances of NSString or NSNumber (or whatever you need)?
Given that you are leaking the array here...
dataCenter.result_array = [[NSMutableArray alloc] initWithArray:Parser_result];
... it is unlikely that this is an over-release problem. Note also that copy with NSMutableArray won't do what you want (the compiler should flag it, but doesn't). -copy always returns an immutable copy of an instance of a class cluster.

EXC_BAD_ACCESS when calling class init in Objective C

I've been trying to figure this out but I can't figure out what I'm doing wrong.
I wrote a class and whenever I try to initialize it, I get a EXC_BAD_ACCESS error. I can't even step into the initialization.
Anyone have any idea what I'm doing wrong?
User *myUser = [myUser init];
.h file:
#import <Foundation/Foundation.h>
#interface User : NSObject {
long rowId;
NSString *email;
NSString *password;
NSString *fileVersion;
}
#property long rowId;
#property (assign) NSString *email;
#property (assign) NSString *password;
#property (assign) NSString *fileVersion;
#end
.m file
#import "User.h"
#implementation User
#synthesize rowId, email, password, fileVersion;
-(id)init {
self = [super init];
return self;
}
#end
You have to actually allocate the object:
User *myUser = [[User alloc] init];
Don't forget to release it when you're done using it.

Cannot figure out how to get rid of memory leak

I'm trying to test for memory leaks in my iphone and I'm not having much luck getting rid of this one. Here is the code that is leaking.
- (id)initWithManagedObjectContext:(NSManagedObjectContext *)aMoc delegate:(id)aDelegate runSync:(BOOL)aRunSync {
if (self = [super init]) {
self.moc = aMoc;
self.settingsManager = [[VacaCalcSettingsManager alloc] initWithManagedObjectContext:self.moc];
self.delegate = aDelegate;
calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
self.runSync = aRunSync;
}
return self;
}
It is leaking on the self.settingsManager = [[VacaCalcSettingsManager alloc] initWithManagedObjectContext:self.moc]; line.
The self.settingManager instance variable is released in the dealloc method of the class.
I'm not sure what other information would be pertinent. Please let me know and I can provide it.
Thanks for any assistance.
-Mark
Here is the header file.
#interface VacaCalcCalculation : NSObject {
NSManagedObjectContext *moc;
VacaCalcSettingsManager *settingsManager;
id delegate;
NSCalendar *calendar;
NSDate *nextBankLimitDate;
BOOL runSync;
}
#property (nonatomic, retain) NSManagedObjectContext *moc;
#property (nonatomic, retain) VacaCalcSettingsManager *settingsManager;
#property (nonatomic, retain) id delegate;
#property (nonatomic, retain) NSCalendar *calendar;
#property (nonatomic, retain) NSDate *nextBankLimitDate;
#property (nonatomic) BOOL runSync;
- (id)initWithManagedObjectContext:(NSManagedObjectContext *)aMoc delegate:(id)aDelegate;
If your settingsManager property is set to retain then you are retaining an object twice with the line: self.settingsManager = [[VacaCalcSettingsManager alloc] initWithManagedObjectContext:self.moc];
Try adding autorelease to the alloc]init or creating a class method on VacaCalcSettingsManager that returns an autoreleased object. Otherwise you could redeclare your property with assign so that it does not retain the object a second time.