瀏覽代碼

use 'guard let self ...' (which is possible since Swift 4.2) instead of 'guard let strongSelf ...', thanks @cyberta

B. Petersen 5 年之前
父節點
當前提交
96c668ea04

+ 4 - 4
Pods/ReachabilitySwift/Sources/Reachability.swift

@@ -224,14 +224,14 @@ fileprivate extension Reachability {
 
     func setReachabilityFlags() throws {
         try reachabilitySerialQueue.sync { [weak self] in
-            guard let strongSelf = self else { return }
+            guard let self = self else { return }
             var flags = SCNetworkReachabilityFlags()
-            if !SCNetworkReachabilityGetFlags(strongSelf.reachabilityRef, &flags) {
-                strongSelf.stopNotifier()
+            if !SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags) {
+                self.stopNotifier()
                 throw ReachabilityError.UnableToGetInitialFlags
             }
             
-            strongSelf.flags = flags
+            self.flags = flags
         }
     }
     

+ 5 - 5
deltachat-ios/Controller/GroupChatDetailViewController.swift

@@ -402,18 +402,18 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
             getGroupMemberIdFor(row) != currentUser.id {
             // action set for members except for current user
             let delete = UITableViewRowAction(style: .destructive, title: String.localized("remove_desktop")) { [weak self] _, indexPath in
-                guard let strongSelf = self else { return }
-                let contact = strongSelf.getGroupMember(at: row)
+                guard let self = self else { return }
+                let contact = self.getGroupMember(at: row)
                 let title = String.localizedStringWithFormat(String.localized("ask_remove_members"), contact.nameNAddr)
                 let alert = UIAlertController(title: title, message: nil, preferredStyle: .safeActionSheet)
                 alert.addAction(UIAlertAction(title: String.localized("remove_desktop"), style: .destructive, handler: { _ in
-                    let success = strongSelf.dcContext.removeContactFromChat(chatId: strongSelf.chat.id, contactId: contact.id)
+                    let success = self.dcContext.removeContactFromChat(chatId: self.chat.id, contactId: contact.id)
                     if success {
-                        strongSelf.removeGroupMemberFromTableAt(indexPath)
+                        self.removeGroupMemberFromTableAt(indexPath)
                     }
                 }))
                 alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
-                strongSelf.present(alert, animated: true, completion: nil)
+                self.present(alert, animated: true, completion: nil)
             }
             delete.backgroundColor = UIColor.red
             return [delete]

+ 8 - 8
deltachat-ios/Controller/NewChatViewController.swift

@@ -229,20 +229,20 @@ class NewChatViewController: UITableViewController {
             let contactId = contactIdByRow(indexPath.row)
 
             let edit = UITableViewRowAction(style: .normal, title: String.localized("info")) { [weak self] _, _ in
-                guard let strongSelf = self else { return }
-                if strongSelf.searchController.isActive {
-                    strongSelf.searchController.dismiss(animated: false) {
-                        strongSelf.showContactDetail(contactId: contactId)
+                guard let self = self else { return }
+                if self.searchController.isActive {
+                    self.searchController.dismiss(animated: false) {
+                        self.showContactDetail(contactId: contactId)
                     }
                 } else {
-                    strongSelf.showContactDetail(contactId: contactId)
+                    self.showContactDetail(contactId: contactId)
                 }
             }
 
             let delete = UITableViewRowAction(style: .destructive, title: String.localized("delete")) { [weak self] _, _ in
-                guard let strongSelf = self else { return }
-                let contactId = strongSelf.contactIdByRow(indexPath.row)
-                strongSelf.askToDeleteContact(contactId: contactId, context: strongSelf.dcContext)
+                guard let self = self else { return }
+                let contactId = self.contactIdByRow(indexPath.row)
+                self.askToDeleteContact(contactId: contactId, context: self.dcContext)
             }
 
             edit.backgroundColor = DcColors.primary

+ 6 - 6
deltachat-ios/Controller/NewGroupController.swift

@@ -255,15 +255,15 @@ class NewGroupController: UITableViewController, MediaPickerDelegate {
         //swipe by delete
         if section == sectionGroupMembers, groupContactIds[row] != DC_CONTACT_ID_SELF {
             let delete = UITableViewRowAction(style: .destructive, title: String.localized("remove_desktop")) { [weak self] _, indexPath in
-                guard let strongSelf = self else { return }
-                if strongSelf.groupChatId != 0,
-                    strongSelf.dcContext.getChat(chatId: strongSelf.groupChatId).contactIds.contains(strongSelf.groupContactIds[row]) {
-                    let success = strongSelf.dcContext.removeContactFromChat(chatId: strongSelf.groupChatId, contactId: strongSelf.groupContactIds[row])
+                guard let self = self else { return }
+                if self.groupChatId != 0,
+                    self.dcContext.getChat(chatId: self.groupChatId).contactIds.contains(self.groupContactIds[row]) {
+                    let success = self.dcContext.removeContactFromChat(chatId: self.groupChatId, contactId: self.groupContactIds[row])
                     if success {
-                        strongSelf.removeGroupContactFromList(at: indexPath)
+                        self.removeGroupContactFromList(at: indexPath)
                     }
                 } else {
-                    strongSelf.removeGroupContactFromList(at: indexPath)
+                    self.removeGroupContactFromList(at: indexPath)
                 }
             }
             delete.backgroundColor = UIColor.red

+ 3 - 3
deltachat-ios/Controller/WelcomeViewController.swift

@@ -15,15 +15,15 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
     private lazy var welcomeView: WelcomeContentView = {
         let view = WelcomeContentView()
         view.onLogin = { [weak self] in
-            guard let strongSelf = self else { return }
-            let accountSetupController = AccountSetupController(dcContext: strongSelf.dcContext, editView: false)
+            guard let self = self else { return }
+            let accountSetupController = AccountSetupController(dcContext: self.dcContext, editView: false)
             accountSetupController.onLoginSuccess = {
                 [weak self] in
                 if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
                     appDelegate.appCoordinator.presentTabBarController()
                 }
             }
-            strongSelf.navigationController?.pushViewController(accountSetupController, animated: true)
+            self.navigationController?.pushViewController(accountSetupController, animated: true)
         }
         view.onScanQRCode  = { [weak self] in
             let qrReader = QrCodeReaderController()