diff --git a/Signal/src/ViewControllers/AdvancedSettingsTableViewController.m b/Signal/src/ViewControllers/AdvancedSettingsTableViewController.m index 97917c80c..19b5909da 100644 --- a/Signal/src/ViewControllers/AdvancedSettingsTableViewController.m +++ b/Signal/src/ViewControllers/AdvancedSettingsTableViewController.m @@ -98,7 +98,7 @@ NS_ASSUME_NONNULL_BEGIN [loggingSection addItem:[OWSTableItem actionItemWithText:NSLocalizedString(@"SETTINGS_ADVANCED_SUBMIT_DEBUGLOG", @"") actionBlock:^{ - DDLogInfo(@"%@ Submitting debug logs", self.tag); + DDLogInfo(@"%@ Submitting debug logs", weakSelf.tag); [DDLog flushLog]; [Pastelog submitLogs]; }]]; diff --git a/Signal/src/ViewControllers/BlockListViewController.m b/Signal/src/ViewControllers/BlockListViewController.m index 527926770..72488c4ad 100644 --- a/Signal/src/ViewControllers/BlockListViewController.m +++ b/Signal/src/ViewControllers/BlockListViewController.m @@ -74,8 +74,6 @@ NS_ASSUME_NONNULL_BEGIN @"A label for the 'add phone number' button in the block list table.") actionBlock:^{ AddToBlockListViewController *vc = [[AddToBlockListViewController alloc] init]; - NSAssert(self.navigationController != nil, @"Navigation controller must not be nil"); - NSAssert(vc != nil, @"Privacy Settings View Controller must not be nil"); [weakSelf.navigationController pushViewController:vc animated:YES]; }]]; [contents addSection:addSection]; diff --git a/Signal/src/ViewControllers/NewGroupViewController.m b/Signal/src/ViewControllers/NewGroupViewController.m index 871282ddb..000d84905 100644 --- a/Signal/src/ViewControllers/NewGroupViewController.m +++ b/Signal/src/ViewControllers/NewGroupViewController.m @@ -216,7 +216,7 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68; [nonContactsSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ NewGroupViewController *strongSelf = weakSelf; - OWSAssert(strongSelf); + OWSCAssert(strongSelf); ContactTableViewCell *cell = [ContactTableViewCell new]; SignalAccount *signalAccount = [contactsViewHelper signalAccountForRecipientId:recipientId]; @@ -309,7 +309,7 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68; [signalAccountSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ NewGroupViewController *strongSelf = weakSelf; - OWSAssert(strongSelf); + OWSCAssert(strongSelf); ContactTableViewCell *cell = [ContactTableViewCell new]; diff --git a/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m b/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m index 8ea19b0f8..c3685bee1 100644 --- a/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m +++ b/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m @@ -271,9 +271,11 @@ NS_ASSUME_NONNULL_BEGIN iconName:@"table_ic_add_to_existing_contact"]; } actionBlock:^{ - TSContactThread *contactThread = (TSContactThread *)self.thread; + OWSConversationSettingsTableViewController *strongSelf = weakSelf; + OWSCAssert(strongSelf); + TSContactThread *contactThread = (TSContactThread *)strongSelf.thread; NSString *recipientId = contactThread.contactIdentifier; - [weakSelf presentAddToContactViewControllerWithRecipientId:recipientId]; + [strongSelf presentAddToContactViewControllerWithRecipientId:recipientId]; }]]; } @@ -293,6 +295,8 @@ NS_ASSUME_NONNULL_BEGIN [mainSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ UITableViewCell *cell = [UITableViewCell new]; + OWSConversationSettingsTableViewController *strongSelf = weakSelf; + OWSCAssert(strongSelf); cell.preservesSuperviewLayoutMargins = YES; cell.contentView.preservesSuperviewLayoutMargins = YES; cell.selectionStyle = UITableViewCellSelectionStyleNone; @@ -303,7 +307,7 @@ NS_ASSUME_NONNULL_BEGIN [topView autoPinEdgeToSuperviewEdge:ALEdgeTop]; [topView autoSetDimension:ALDimensionHeight toSize:kOWSTable_DefaultCellHeight]; - UIImageView *iconView = [self viewForIconWithName:@"table_ic_hourglass"]; + UIImageView *iconView = [strongSelf viewForIconWithName:@"table_ic_hourglass"]; [topView addSubview:iconView]; [iconView autoVCenterInSuperview]; [iconView autoPinLeadingToSuperView]; @@ -318,8 +322,8 @@ NS_ASSUME_NONNULL_BEGIN [rowLabel autoPinLeadingToTrailingOfView:iconView margin:weakSelf.iconSpacing]; UISwitch *switchView = [UISwitch new]; - switchView.on = self.disappearingMessagesConfiguration.isEnabled; - [switchView addTarget:self + switchView.on = strongSelf.disappearingMessagesConfiguration.isEnabled; + [switchView addTarget:strongSelf action:@selector(disappearingMessagesSwitchValueDidChange:) forControlEvents:UIControlEventValueChanged]; [topView addSubview:switchView]; @@ -350,6 +354,8 @@ NS_ASSUME_NONNULL_BEGIN addItem:[OWSTableItem itemWithCustomCellBlock:^{ UITableViewCell *cell = [UITableViewCell new]; + OWSConversationSettingsTableViewController *strongSelf = weakSelf; + OWSCAssert(strongSelf); cell.preservesSuperviewLayoutMargins = YES; cell.contentView.preservesSuperviewLayoutMargins = YES; cell.selectionStyle = UITableViewCellSelectionStyleNone; @@ -360,13 +366,13 @@ NS_ASSUME_NONNULL_BEGIN [topView autoPinEdgeToSuperviewEdge:ALEdgeTop]; [topView autoSetDimension:ALDimensionHeight toSize:kOWSTable_DefaultCellHeight]; - UIImageView *iconView = [self viewForIconWithName:@"table_ic_hourglass"]; + UIImageView *iconView = [strongSelf viewForIconWithName:@"table_ic_hourglass"]; [topView addSubview:iconView]; [iconView autoVCenterInSuperview]; [iconView autoPinLeadingToSuperView]; - UILabel *rowLabel = self.disappearingMessagesDurationLabel; - [self updateDisappearingMessagesDurationLabel]; + UILabel *rowLabel = strongSelf.disappearingMessagesDurationLabel; + [strongSelf updateDisappearingMessagesDurationLabel]; rowLabel.textColor = [UIColor blackColor]; rowLabel.font = [UIFont ows_footnoteFont]; rowLabel.lineBreakMode = NSLineBreakByTruncatingTail; @@ -375,11 +381,11 @@ NS_ASSUME_NONNULL_BEGIN [rowLabel autoPinLeadingToTrailingOfView:iconView margin:weakSelf.iconSpacing]; UISlider *slider = [UISlider new]; - slider.maximumValue = (float)(self.disappearingMessagesDurations.count - 1); + slider.maximumValue = (float)(strongSelf.disappearingMessagesDurations.count - 1); slider.minimumValue = 0; slider.continuous = YES; // NO fires change event only once you let go - slider.value = self.disappearingMessagesConfiguration.durationIndex; - [slider addTarget:self + slider.value = strongSelf.disappearingMessagesConfiguration.durationIndex; + [slider addTarget:strongSelf action:@selector(durationSliderDidChange:) forControlEvents:UIControlEventValueChanged]; [cell.contentView addSubview:slider]; @@ -436,11 +442,13 @@ NS_ASSUME_NONNULL_BEGIN OWSTableSection *muteSection = [OWSTableSection new]; [muteSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil]; + OWSConversationSettingsTableViewController *strongSelf = weakSelf; + OWSCAssert(strongSelf); cell.preservesSuperviewLayoutMargins = YES; cell.contentView.preservesSuperviewLayoutMargins = YES; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; - UIImageView *iconView = [self viewForIconWithName:@"table_ic_mute_thread"]; + UIImageView *iconView = [strongSelf viewForIconWithName:@"table_ic_mute_thread"]; [cell.contentView addSubview:iconView]; [iconView autoVCenterInSuperview]; [iconView autoPinLeadingToSuperView]; @@ -457,7 +465,7 @@ NS_ASSUME_NONNULL_BEGIN NSString *muteStatus = NSLocalizedString( @"CONVERSATION_SETTINGS_MUTE_NOT_MUTED", @"Indicates that the current thread is not muted."); - NSDate *mutedUntilDate = self.thread.mutedUntilDate; + NSDate *mutedUntilDate = strongSelf.thread.mutedUntilDate; NSDate *now = [NSDate date]; if (mutedUntilDate != nil && [mutedUntilDate timeIntervalSinceDate:now] > 0) { NSCalendar *calendar = [NSCalendar currentCalendar]; @@ -506,11 +514,13 @@ NS_ASSUME_NONNULL_BEGIN [weakSelf disclosureCellWithName:NSLocalizedString(@"CONVERSATION_SETTINGS_BLOCK_THIS_USER", @"table cell label in conversation settings") iconName:@"table_ic_block"]; + OWSConversationSettingsTableViewController *strongSelf = weakSelf; + OWSCAssert(strongSelf); cell.selectionStyle = UITableViewCellSelectionStyleNone; UISwitch *blockUserSwitch = [UISwitch new]; blockUserSwitch.on = isBlocked; - [blockUserSwitch addTarget:self + [blockUserSwitch addTarget:strongSelf action:@selector(blockUserSwitchDidChange:) forControlEvents:UIControlEventValueChanged]; cell.accessoryView = blockUserSwitch; @@ -521,7 +531,6 @@ NS_ASSUME_NONNULL_BEGIN } self.contents = contents; - [self.tableView reloadData]; } - (CGFloat)iconSpacing @@ -892,7 +901,7 @@ NS_ASSUME_NONNULL_BEGIN { self.disappearingMessagesConfiguration.enabled = flag; - [self.tableView reloadData]; + [self updateTableContents]; } - (void)durationSliderDidChange:(UISlider *)slider @@ -1045,7 +1054,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)setThreadMutedUntilDate:(nullable NSDate *)value { [self.thread updateWithMutedUntilDate:value]; - [self.tableView reloadData]; + [self updateTableContents]; } #pragma mark - Notifications diff --git a/Signal/src/ViewControllers/OWSTableViewController.m b/Signal/src/ViewControllers/OWSTableViewController.m index 7091a8abc..a68de2c9d 100644 --- a/Signal/src/ViewControllers/OWSTableViewController.m +++ b/Signal/src/ViewControllers/OWSTableViewController.m @@ -282,10 +282,12 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f; selector:(SEL)selector { OWSAssert(text.length > 0); + OWSAssert(target); OWSAssert(selector); OWSTableItem *item = [OWSTableItem new]; item.itemType = OWSTableItemTypeAction; + __weak id weakTarget = target; item.customCellBlock = ^{ UITableViewCell *cell = [UITableViewCell new]; cell.textLabel.text = text; @@ -295,7 +297,7 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f; UISwitch *cellSwitch = [UISwitch new]; cell.accessoryView = cellSwitch; [cellSwitch setOn:isOn]; - [cellSwitch addTarget:target action:selector forControlEvents:UIControlEventValueChanged]; + [cellSwitch addTarget:weakTarget action:selector forControlEvents:UIControlEventValueChanged]; cellSwitch.enabled = isEnabled; cell.selectionStyle = UITableViewCellSelectionStyleNone; diff --git a/Signal/src/ViewControllers/PrivacySettingsTableViewController.m b/Signal/src/ViewControllers/PrivacySettingsTableViewController.m index 66e7e6b14..d1b8e1836 100644 --- a/Signal/src/ViewControllers/PrivacySettingsTableViewController.m +++ b/Signal/src/ViewControllers/PrivacySettingsTableViewController.m @@ -96,7 +96,6 @@ NS_ASSUME_NONNULL_BEGIN }]]; [contents addSection:historyLogsSection]; - self.contents = contents; } diff --git a/Signal/src/ViewControllers/SelectRecipientViewController.m b/Signal/src/ViewControllers/SelectRecipientViewController.m index 572f7c2ab..0f43a5937 100644 --- a/Signal/src/ViewControllers/SelectRecipientViewController.m +++ b/Signal/src/ViewControllers/SelectRecipientViewController.m @@ -446,7 +446,6 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien - (void)updateTableContents { OWSTableContents *contents = [OWSTableContents new]; - __weak SelectRecipientViewController *weakSelf = self; ContactsViewHelper *helper = self.contactsViewHelper; @@ -458,57 +457,59 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien const CGFloat kButtonRowHeight = 60; [phoneNumberSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ SelectRecipientViewController *strongSelf = weakSelf; - OWSAssert(strongSelf); + OWSCAssert(strongSelf); UITableViewCell *cell = [UITableViewCell new]; cell.preservesSuperviewLayoutMargins = YES; cell.contentView.preservesSuperviewLayoutMargins = YES; // Country Row - UIView *countryRow = [self createRowWithHeight:kCountryRowHeight previousRow:nil superview:cell.contentView]; - [countryRow addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self + UIView *countryRow = + [strongSelf createRowWithHeight:kCountryRowHeight previousRow:nil superview:cell.contentView]; + [countryRow addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:strongSelf action:@selector(countryRowTouched:)]]; - UILabel *countryCodeLabel = self.countryCodeLabel; + UILabel *countryCodeLabel = strongSelf.countryCodeLabel; [countryRow addSubview:countryCodeLabel]; [countryCodeLabel autoPinLeadingToSuperView]; [countryCodeLabel autoVCenterInSuperview]; - [countryRow addSubview:self.countryCodeButton]; - [self.countryCodeButton autoPinTrailingToSuperView]; - [self.countryCodeButton autoVCenterInSuperview]; + [countryRow addSubview:strongSelf.countryCodeButton]; + [strongSelf.countryCodeButton autoPinTrailingToSuperView]; + [strongSelf.countryCodeButton autoVCenterInSuperview]; // Phone Number Row UIView *phoneNumberRow = - [self createRowWithHeight:kPhoneNumberRowHeight previousRow:countryRow superview:cell.contentView]; + [strongSelf createRowWithHeight:kPhoneNumberRowHeight previousRow:countryRow superview:cell.contentView]; [phoneNumberRow - addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self + addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:strongSelf action:@selector(phoneNumberRowTouched:)]]; - UILabel *phoneNumberLabel = self.phoneNumberLabel; + UILabel *phoneNumberLabel = strongSelf.phoneNumberLabel; [phoneNumberRow addSubview:phoneNumberLabel]; [phoneNumberLabel autoPinLeadingToSuperView]; [phoneNumberLabel autoVCenterInSuperview]; - [phoneNumberRow addSubview:self.phoneNumberTextField]; - [self.phoneNumberTextField autoPinLeadingToTrailingOfView:phoneNumberLabel margin:10.f]; - [self.phoneNumberTextField autoPinTrailingToSuperView]; - [self.phoneNumberTextField autoVCenterInSuperview]; + [phoneNumberRow addSubview:strongSelf.phoneNumberTextField]; + [strongSelf.phoneNumberTextField autoPinLeadingToTrailingOfView:phoneNumberLabel margin:10.f]; + [strongSelf.phoneNumberTextField autoPinTrailingToSuperView]; + [strongSelf.phoneNumberTextField autoVCenterInSuperview]; // Example row. - UIView *examplePhoneNumberRow = [self createRowWithHeight:examplePhoneNumberRowHeight - previousRow:phoneNumberRow - superview:cell.contentView]; - [examplePhoneNumberRow addSubview:self.examplePhoneNumberLabel]; - [self.examplePhoneNumberLabel autoVCenterInSuperview]; - [self.examplePhoneNumberLabel autoPinTrailingToSuperView]; + UIView *examplePhoneNumberRow = [strongSelf createRowWithHeight:examplePhoneNumberRowHeight + previousRow:phoneNumberRow + superview:cell.contentView]; + [examplePhoneNumberRow addSubview:strongSelf.examplePhoneNumberLabel]; + [strongSelf.examplePhoneNumberLabel autoVCenterInSuperview]; + [strongSelf.examplePhoneNumberLabel autoPinTrailingToSuperView]; // Phone Number Button Row - UIView *buttonRow = - [self createRowWithHeight:kButtonRowHeight previousRow:examplePhoneNumberRow superview:cell.contentView]; - [buttonRow addSubview:self.phoneNumberButton]; - [self.phoneNumberButton autoVCenterInSuperview]; - [self.phoneNumberButton autoPinTrailingToSuperView]; + UIView *buttonRow = [strongSelf createRowWithHeight:kButtonRowHeight + previousRow:examplePhoneNumberRow + superview:cell.contentView]; + [buttonRow addSubview:strongSelf.phoneNumberButton]; + [strongSelf.phoneNumberButton autoVCenterInSuperview]; + [strongSelf.phoneNumberButton autoPinTrailingToSuperView]; [buttonRow autoPinEdgeToSuperviewEdge:ALEdgeBottom]; @@ -538,7 +539,7 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien for (SignalAccount *signalAccount in signalAccounts) { [contactsSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ SelectRecipientViewController *strongSelf = weakSelf; - OWSAssert(strongSelf); + OWSCAssert(strongSelf); ContactTableViewCell *cell = [ContactTableViewCell new]; BOOL isBlocked = [helper isRecipientIdBlocked:signalAccount.recipientId]; diff --git a/Signal/src/ViewControllers/SelectThreadViewController.m b/Signal/src/ViewControllers/SelectThreadViewController.m index ac759faf9..268ffc1ca 100644 --- a/Signal/src/ViewControllers/SelectThreadViewController.m +++ b/Signal/src/ViewControllers/SelectThreadViewController.m @@ -136,7 +136,7 @@ NS_ASSUME_NONNULL_BEGIN for (TSThread *thread in [self filteredThreadsWithSearchText]) { [section addItem:[OWSTableItem itemWithCustomCellBlock:^{ SelectThreadViewController *strongSelf = weakSelf; - OWSAssert(strongSelf); + OWSCAssert(strongSelf); // To be consistent with the threads (above), we use ContactTableViewCell // instead of InboxTableViewCell to present contacts and threads. @@ -155,7 +155,7 @@ NS_ASSUME_NONNULL_BEGIN for (SignalAccount *signalAccount in filteredSignalAccounts) { [section addItem:[OWSTableItem itemWithCustomCellBlock:^{ SelectThreadViewController *strongSelf = weakSelf; - OWSAssert(strongSelf); + OWSCAssert(strongSelf); ContactTableViewCell *cell = [ContactTableViewCell new]; BOOL isBlocked = [helper isRecipientIdBlocked:signalAccount.recipientId]; diff --git a/Signal/src/ViewControllers/SettingsTableViewController.m b/Signal/src/ViewControllers/SettingsTableViewController.m index cfa8f155f..113e10ee0 100644 --- a/Signal/src/ViewControllers/SettingsTableViewController.m +++ b/Signal/src/ViewControllers/SettingsTableViewController.m @@ -239,8 +239,6 @@ - (void)showPrivacy { PrivacySettingsTableViewController *vc = [[PrivacySettingsTableViewController alloc] init]; - NSAssert(self.navigationController != nil, @"Navigation controller must not be nil"); - NSAssert(vc != nil, @"Privacy Settings View Controller must not be nil"); [self.navigationController pushViewController:vc animated:YES]; } @@ -260,16 +258,12 @@ - (void)showAdvanced { AdvancedSettingsTableViewController *vc = [[AdvancedSettingsTableViewController alloc] init]; - NSAssert(self.navigationController != nil, @"Navigation controller must not be nil"); - NSAssert(vc != nil, @"Advanced Settings View Controller must not be nil"); [self.navigationController pushViewController:vc animated:YES]; } - (void)showAbout { AboutTableViewController *vc = [[AboutTableViewController alloc] init]; - NSAssert(self.navigationController != nil, @"Navigation controller must not be nil"); - NSAssert(vc != nil, @"About View Controller must not be nil"); [self.navigationController pushViewController:vc animated:YES]; } diff --git a/Signal/src/ViewControllers/ShowGroupMembersViewController.m b/Signal/src/ViewControllers/ShowGroupMembersViewController.m index 2113f26a9..605aaedba 100644 --- a/Signal/src/ViewControllers/ShowGroupMembersViewController.m +++ b/Signal/src/ViewControllers/ShowGroupMembersViewController.m @@ -169,7 +169,7 @@ NS_ASSUME_NONNULL_BEGIN for (NSString *recipientId in [recipientIds sortedArrayUsingSelector:@selector(compare:)]) { [section addItem:[OWSTableItem itemWithCustomCellBlock:^{ ShowGroupMembersViewController *strongSelf = weakSelf; - OWSAssert(strongSelf); + OWSCAssert(strongSelf); ContactTableViewCell *cell = [ContactTableViewCell new]; SignalAccount *signalAccount = [helper signalAccountForRecipientId:recipientId]; diff --git a/Signal/src/ViewControllers/UpdateGroupViewController.m b/Signal/src/ViewControllers/UpdateGroupViewController.m index ba200a737..22e48a76c 100644 --- a/Signal/src/ViewControllers/UpdateGroupViewController.m +++ b/Signal/src/ViewControllers/UpdateGroupViewController.m @@ -265,7 +265,7 @@ NS_ASSUME_NONNULL_BEGIN [section addItem:[OWSTableItem itemWithCustomCellBlock:^{ UpdateGroupViewController *strongSelf = weakSelf; - OWSAssert(strongSelf); + OWSCAssert(strongSelf); ContactTableViewCell *cell = [ContactTableViewCell new]; SignalAccount *signalAccount = [contactsViewHelper signalAccountForRecipientId:recipientId];