Skip to content

nil unsafe delegates and data sources at dealloc #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ - (instancetype)initWithIdentifier:(NSString*)identifier
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
_locationManager.delegate = nil;
}

- (void)setupInitialLocationParameters
Expand All @@ -126,6 +127,7 @@ - (void)startTracking
if ([CLLocationManager locationServicesEnabled] == YES)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • (void)startTracking
    {
    if ([CLLocationManager locationServicesEnabled] == YES)
    {
    APCLogDebug(@"Start location tracking");
    •    self.locationManager.delegate = nil;
      
      self.locationManager = [[CLLocationManager alloc] init];
      self.locationManager.delegate = self;

just curious why you're allocating a whole new CLLocationManager every time you start and stop tracking, rather than creating it once and then starting/stopping SignificantLocationChanges as needed...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'd be a valid approach as well. Easy to just check if self.locationManager isn't nil if you wanted to do it that way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raised #7 for doing this in future.

{
APCLogDebug(@"Start location tracking");
self.locationManager.delegate = nil;
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ @interface APCMedicationTrackerCalendarViewController ( ) <UITableViewDataSourc

@implementation APCMedicationTrackerCalendarViewController

- (void)dealloc {
_exScrollibur.delegate = nil;
_tabulator.delegate = nil;
_tabulator.dataSource = nil;
}

#pragma mark - Table View Data Source Methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *) __unused tableView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ - (id)initWithFrame:(CGRect)frame
return self;
}

- (void)dealloc {
_leftSwiper.delegate = nil;
_rightSwiper.delegate = nil;
}

- (void)setupViews
{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ @interface APCMedicationTrackerDetailViewController ( ) <UITableViewDataSource

@implementation APCMedicationTrackerDetailViewController

- (void)dealloc {
_tabulator.delegate = nil;
_tabulator.dataSource = nil;
}

#pragma mark - Table View Data Source Methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *) __unused tableView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ @interface APCMedicationDosageViewController ( ) <UITableViewDataSource, UITab

@implementation APCMedicationDosageViewController

- (void)dealloc {
_tabulator.delegate = nil;
_tabulator.dataSource = nil;
}

#pragma mark - Navigation Bar Button Action Methods

- (void)doneButtonTapped:(UIBarButtonItem *) __unused sender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ @interface APCMedicationFrequencyViewController ( ) <UITableViewDataSource, UI

@implementation APCMedicationFrequencyViewController

- (void)dealloc {
_tabulator.delegate = nil;
_tabulator.dataSource = nil;
}

#pragma mark - Table View Data Source Methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *) __unused tableView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ @interface APCMedicationColorViewController ( ) <UITableViewDataSource, UITabl

@implementation APCMedicationColorViewController

- (void)dealloc {
_tabulator.delegate = nil;
_tabulator.dataSource = nil;
}

#pragma mark - Navigation Bar Button Action Methods

- (IBAction)doneButtonTapped:(UIBarButtonItem *) __unused sender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ @interface APCMedicationNameViewController ( ) <UITableViewDataSource, UITable

@implementation APCMedicationNameViewController


- (void)dealloc {
_tabulator.delegate = nil;
_tabulator.dataSource = nil;
}

#pragma mark - Navigation Bar Button Action Methods

- (void)doneButtonTapped:(UIBarButtonItem *) __unused sender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ @interface APCMedicationTrackerSetupViewController ( ) <UITableViewDataSource,

@implementation APCMedicationTrackerSetupViewController

- (void)dealloc {
_setupTabulator.delegate = nil;
_setupTabulator.dataSource = nil;
_listTabulator.delegate = nil;
_listTabulator.dataSource = nil;
}

#pragma mark - Table View Data Source Methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *) __unused tableView
Expand Down
4 changes: 4 additions & 0 deletions APCAppCore/APCAppCore/Library/Parameters/APCParametersCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ @interface APCParametersCell ()

@implementation APCParametersCell

- (void)dealloc {
_parameterTextInput.delegate = nil;
}

- (void)awakeFromNib {
// Initialization code
[self.parameterTextInput setDelegate:self];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ - (void)appDidRegisterForRemoteNotifications: (NSNotification *)notification
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
_locationManager.delegate = nil;
}

@end
9 changes: 7 additions & 2 deletions APCAppCore/APCAppCore/UI/Onboarding/APCShareViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ @interface APCShareViewController () <MFMessageComposeViewControllerDelegate, MF

@implementation APCShareViewController

- (void)dealloc {
_tableView.delegate = nil;
_tableView.dataSource = nil;
}

- (void)viewDidLoad {
[super viewDidLoad];

Expand Down Expand Up @@ -251,7 +256,7 @@ - (void)mailComposeController:(MFMailComposeViewController *)controller didFinis
default:
break;
}

controller.delegate = nil;
[controller dismissViewControllerAnimated:YES completion:nil];
}

Expand All @@ -270,7 +275,7 @@ - (void)messageComposeViewController:(MFMessageComposeViewController *)controlle
default:
break;
}

controller.delegate = nil;
[controller dismissViewControllerAnimated:YES completion:nil];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ @interface APCStudyDetailsViewController () <UIWebViewDelegate>

@implementation APCStudyDetailsViewController

- (void)dealloc {
_webView.delegate = nil;
}

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ -(void)viewDidAppear:(BOOL)animated {
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:APCConsentCompletedWithDisagreeNotification object:nil];
_collectionView.delegate = nil;
}

- (void) goBackToSignUpJoin: (NSNotification *) __unused notification
Expand Down Expand Up @@ -436,7 +437,7 @@ - (void)mailComposeController:(MFMailComposeViewController *)controller didFinis
default:
break;
}

controller.mailComposeDelegate = nil;
[controller dismissViewControllerAnimated:YES completion:nil];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ @interface APCStudyOverviewViewController () <ORKTaskViewControllerDelegate>

@implementation APCStudyOverviewViewController


#pragma mark - Lifecycle

- (void)viewDidLoad {
Expand Down Expand Up @@ -85,6 +84,8 @@ - (void)viewWillAppear:(BOOL)animated
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:APCConsentCompletedWithDisagreeNotification object:nil];
_tableView.delegate = nil;
_tableView.dataSource = nil;
}

- (void)goBackToSignUpJoin:(NSNotification *) __unused notification
Expand Down
4 changes: 4 additions & 0 deletions APCAppCore/APCAppCore/UI/Onboarding/APCWebViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ @interface APCWebViewController ()

@implementation APCWebViewController

- (void)dealloc {
_webview.delegate = nil;
}

-(void)viewDidLoad{
self.webview.delegate = self;
self.webview.alpha = 0.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ @interface APCChangeEmailViewController ()

@implementation APCChangeEmailViewController

- (void)dealloc {
_emailTextField.delegate = nil;
}

- (void)viewDidLoad {
[super viewDidLoad];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ @interface APCForgotPasswordViewController ()

@implementation APCForgotPasswordViewController

- (void)dealloc {
_emailTextField.delegate = nil;
}

- (void)viewDidLoad
{
[super viewDidLoad];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ @interface APCSignInViewController () <ORKTaskViewControllerDelegate>

@implementation APCSignInViewController

- (void)dealloc {
_userHandleTextField.delegate = nil;
_passwordTextField.delegate = nil;
}

#pragma mark - Life Cycle

- (void)viewDidLoad {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,12 @@ - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickin

[self.profileImageButton setImage:image forState:UIControlStateNormal];

picker.delegate = nil;
[picker dismissViewControllerAnimated:YES completion:nil];
}

- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker {
picker.delegate = nil;
[picker dismissViewControllerAnimated:YES completion:nil];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ @implementation APCSignUpInfoViewController
@synthesize stepProgressBar;
@synthesize user = _user;

- (void)dealloc {
_nameTextField.delegate = nil;
_emailTextField.delegate = nil;
}

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ @interface APCProfileViewController () <ORKTaskViewControllerDelegate>

@implementation APCProfileViewController

- (void)dealloc {
_nameTextField.delegate = nil;
}

- (void)viewDidLoad {
[super viewDidLoad];
NSString *build = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
Expand Down Expand Up @@ -1166,11 +1170,13 @@ - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickin
self.profileImage = image;
[self.profileImageButton setImage:image forState:UIControlStateNormal];
self.user.profileImage = UIImagePNGRepresentation(image);
picker.delegate = nil;
[picker dismissViewControllerAnimated:YES completion:nil];
}

- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
picker.delegate = nil;
[picker dismissViewControllerAnimated:YES completion:nil];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ @interface APCSharingOptionsViewController()

@implementation APCSharingOptionsViewController

- (void)dealloc {
_tableView.delegate = nil;
_tableView.dataSource = nil;
}

- (void)viewDidLoad
{
[super viewDidLoad];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ @interface APCWithdrawSurveyViewController ()<APCWithdrawDescriptionViewControll

@implementation APCWithdrawSurveyViewController

- (void)dealloc {
_tableView.delegate = nil;
_tableView.dataSource = nil;
}

- (void)viewDidLoad {
[super viewDidLoad];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ - (void)awakeFromNib {
self.pickerView.delegate = self;
}

- (void)dealloc {
_pickerView.delegate = nil;
_pickerView.dataSource = nil;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ - (void)awakeFromNib {
[self setupAppearance];
}

- (void)dealloc {
_textField.delegate = nil;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ @interface APCIntroductionViewController ( ) <UIScrollViewDelegate>

@implementation APCIntroductionViewController

- (void)dealloc {
_textScroller.delegate = nil;
_imageScroller.delegate = nil;
}

#pragma mark - Initialise Scroll View With Images

- (void)initialiseImageScrollView
Expand Down
4 changes: 4 additions & 0 deletions APCAppCore/APCAppCore/UI/Views/APCPasscodeView.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ - (instancetype) initWithFrame:(CGRect)frame {
return self;
}

- (void)dealloc {
_hiddenTextField.delegate = nil;
}

- (void) addControls {
_digitViews = [NSMutableArray new];

Expand Down