diff --git a/Yep/Realm/Models.swift b/Yep/Realm/Models.swift index a62eeb1e..210b6883 100644 --- a/Yep/Realm/Models.swift +++ b/Yep/Realm/Models.swift @@ -402,6 +402,7 @@ func tryCreateSectionDateMessageInConversation(conversation: Conversation, befor newSectionDateMessage.conversation = conversation newSectionDateMessage.mediaType = MessageMediaType.SectionDate.rawValue newSectionDateMessage.createdUnixTime = message.createdUnixTime - 1 // 比新消息早一秒 + newSectionDateMessage.messageID = "sectionDate-\(newSectionDateMessage.createdUnixTime)" success(newSectionDateMessage) } diff --git a/Yep/Services/YepServiceSync.swift b/Yep/Services/YepServiceSync.swift index ae0f5a0f..4c884c0e 100644 --- a/Yep/Services/YepServiceSync.swift +++ b/Yep/Services/YepServiceSync.swift @@ -965,10 +965,10 @@ func syncMessageWithMessageInfo(messageInfo: JSONDictionary, inRealm realm: Real message.conversation = conversation - var createdSectionDateMessage = false + var sectionDateMessageID: String? tryCreateSectionDateMessageInConversation(conversation, beforeMessage: message, inRealm: realm) { sectionDateMessage in realm.add(sectionDateMessage) - createdSectionDateMessage = true + sectionDateMessageID = sectionDateMessage.messageID } // 纪录消息的 detail 信息 @@ -1050,8 +1050,8 @@ func syncMessageWithMessageInfo(messageInfo: JSONDictionary, inRealm realm: Real // Do furtherAction after sync //println("syncMessageWithMessageInfo do furtherAction") - if createdSectionDateMessage { - furtherAction?(messageIDs: ["", messageID]) + if let sectionDateMessageID = sectionDateMessageID{ + furtherAction?(messageIDs: [sectionDateMessageID, messageID]) } else { furtherAction?(messageIDs: [messageID]) } diff --git a/Yep/ViewControllers/Contacts/ContactsViewController.swift b/Yep/ViewControllers/Contacts/ContactsViewController.swift index 3d9991cd..1c8ee89f 100644 --- a/Yep/ViewControllers/Contacts/ContactsViewController.swift +++ b/Yep/ViewControllers/Contacts/ContactsViewController.swift @@ -34,11 +34,11 @@ class ContactsViewController: BaseViewController { contactsTableView.rowHeight = 80 contactsTableView.tableFooterView = UIView() - YepUserDefaults.nickname.bindListener("ContactsViewController.Nickname") { _ in + YepUserDefaults.nickname.bindListener("ContactsViewController.Nickname") { [unowned self] _ in self.updateContactsTableView() } - YepUserDefaults.avatarURLString.bindListener("ContactsViewController.Avatar") { _ in + YepUserDefaults.avatarURLString.bindListener("ContactsViewController.Avatar") { [unowned self] _ in self.updateContactsTableView() } } diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index 1ec3556a..d73f4256 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -240,7 +240,7 @@ class ConversationViewController: BaseViewController { NSNotificationCenter.defaultCenter().addObserver(self, selector: "cleanForLogout", name: EditProfileViewController.Notification.Logout, object: nil) - YepUserDefaults.avatarURLString.bindListener("ConversationViewController") { _ in + YepUserDefaults.avatarURLString.bindListener("ConversationViewController") { [unowned self] _ in self.reloadConversationCollectionView() } @@ -271,7 +271,7 @@ class ConversationViewController: BaseViewController { lastTimeMessagesCount = messages.count - messageToolbar.textSendAction = { messageToolbar in + messageToolbar.textSendAction = { [unowned self] messageToolbar in let text = messageToolbar.messageTextView.text! self.cleanTextInput() @@ -294,10 +294,10 @@ class ConversationViewController: BaseViewController { }) } else if let withGroup = self.conversation.withGroup { - sendText(text, toRecipient: withGroup.groupID, recipientType: "Circle", afterCreatedMessage: { message in + sendText(text, toRecipient: withGroup.groupID, recipientType: "Circle", afterCreatedMessage: { [unowned self] message in dispatch_async(dispatch_get_main_queue()) { - self.updateConversationCollectionViewWithMessageIDs(nil, scrollToBottom: true, success: { success in + self.updateConversationCollectionViewWithMessageIDs(nil, scrollToBottom: true, success: { _ in }) } @@ -319,7 +319,7 @@ class ConversationViewController: BaseViewController { //println("Update waver") audioRecorder.updateMeters() - var normalizedValue = pow(10, audioRecorder.averagePowerForChannel(0)/40) + let normalizedValue = pow(10, audioRecorder.averagePowerForChannel(0)/40) waver.level = CGFloat(normalizedValue) } @@ -328,7 +328,7 @@ class ConversationViewController: BaseViewController { // MARK: Audio Send - messageToolbar.voiceSendBeginAction = { messageToolbar in + messageToolbar.voiceSendBeginAction = { [unowned self] messageToolbar in self.view.addSubview(self.waverView) self.swipeUpView.hidden = false self.view.bringSubviewToFront(self.swipeUpView) @@ -351,13 +351,13 @@ class ConversationViewController: BaseViewController { } } - messageToolbar.voiceSendCancelAction = { messageToolbar in + messageToolbar.voiceSendCancelAction = { [unowned self] messageToolbar in self.swipeUpView.hidden = true self.waverView.removeFromSuperview() YepAudioService.sharedManager.endRecord() } - messageToolbar.voiceSendEndAction = { messageToolbar in + messageToolbar.voiceSendEndAction = { [unowned self] messageToolbar in self.swipeUpView.hidden = true self.waverView.removeFromSuperview() if YepAudioService.sharedManager.audioRecorder?.currentTime < 0.5 { @@ -398,7 +398,7 @@ class ConversationViewController: BaseViewController { if let fileURL = YepAudioService.sharedManager.audioFileURL { if let withFriend = self.conversation.withFriend { - sendAudioInFilePath(fileURL.path!, orFileData: nil, metaData: metaData, toRecipient: withFriend.userID, recipientType: "User", afterCreatedMessage: { message -> Void in + sendAudioInFilePath(fileURL.path!, orFileData: nil, metaData: metaData, toRecipient: withFriend.userID, recipientType: "User", afterCreatedMessage: { [unowned self] message in dispatch_async(dispatch_get_main_queue()) { if let realm = message.realm { @@ -410,7 +410,7 @@ class ConversationViewController: BaseViewController { } realm.commitWrite() - self.updateConversationCollectionViewWithMessageIDs(nil, scrollToBottom: true, success: { success in + self.updateConversationCollectionViewWithMessageIDs(nil, scrollToBottom: true, success: { _ in }) } } @@ -424,7 +424,7 @@ class ConversationViewController: BaseViewController { }) } else if let withGroup = self.conversation.withGroup { - sendAudioInFilePath(fileURL.path!, orFileData: nil, metaData: metaData, toRecipient: withGroup.groupID, recipientType: "Circle", afterCreatedMessage: { (message) -> Void in + sendAudioInFilePath(fileURL.path!, orFileData: nil, metaData: metaData, toRecipient: withGroup.groupID, recipientType: "Circle", afterCreatedMessage: { [unowned self] message in dispatch_async(dispatch_get_main_queue()) { if let realm = message.realm { @@ -436,7 +436,7 @@ class ConversationViewController: BaseViewController { } realm.commitWrite() - self.updateConversationCollectionViewWithMessageIDs(nil, scrollToBottom: true, success: { success in + self.updateConversationCollectionViewWithMessageIDs(nil, scrollToBottom: true, success: { _ in }) } } @@ -454,7 +454,7 @@ class ConversationViewController: BaseViewController { // MARK: MessageToolbar State Transitions - messageToolbar.stateTransitionAction = { (messageToolbar, previousState, currentState) in + messageToolbar.stateTransitionAction = { [unowned self] (messageToolbar, previousState, currentState) in switch (previousState, currentState) { @@ -884,15 +884,19 @@ class ConversationViewController: BaseViewController { messageIDs = _messageIDs } - updateConversationCollectionViewWithMessageIDs(messageIDs, scrollToBottom: false, success: { success in + updateConversationCollectionViewWithMessageIDs(messageIDs, scrollToBottom: false, success: { _ in }) } func updateConversationCollectionViewWithMessageIDs(messageIDs: [String]?, scrollToBottom: Bool, success: (Bool) -> Void) { - let keyboardAndToolBarHeight = messageToolbarBottomConstraint.constant + CGRectGetHeight(messageToolbar.bounds) - adjustConversationCollectionViewWithMessageIDs(messageIDs, adjustHeight: keyboardAndToolBarHeight, scrollToBottom: scrollToBottom) { finished in - success(finished) + if navigationController?.topViewController == self { // 防止 pop/push 后,原来未释放的 VC 也执行这下面的代码 + + let keyboardAndToolBarHeight = messageToolbarBottomConstraint.constant + CGRectGetHeight(messageToolbar.bounds) + + adjustConversationCollectionViewWithMessageIDs(messageIDs, adjustHeight: keyboardAndToolBarHeight, scrollToBottom: scrollToBottom) { finished in + success(finished) + } } } @@ -910,12 +914,11 @@ class ConversationViewController: BaseViewController { let lastDisplayedMessagesRange = displayedMessagesRange displayedMessagesRange.length += newMessagesCount - - var indexPaths = [NSIndexPath]() - + if newMessagesCount > 0 { /* + //var indexPaths = [NSIndexPath]() // TODO: 下面插入逻辑的假设有问题,对方的新消息并不会一直排在最后一个 for i in 0.. 0 { - println("have sectionDate") - conversationCollectionView.reloadData() + var indexPaths = [NSIndexPath]() - } else { + for messageID in messageIDs { + if let + message = messageWithMessageID(messageID, inRealm: realm), + index = messages.indexOf(message), + indexPath = NSIndexPath(forItem: index - displayedMessagesRange.location, inSection: 0) { + println("insert item: \(indexPath.item)") - var indexPaths = [NSIndexPath]() + indexPaths.append(indexPath) - for messageID in messageIDs { - if let - message = messageWithMessageID(messageID, inRealm: realm), - index = messages.indexOf(message), - indexPath = NSIndexPath(forItem: index - displayedMessagesRange.location, inSection: 0) { - println("insert item: \(indexPath.item)") - - indexPaths.append(indexPath) - - } else { - println("unknown message") - } + } else { + println("unknown message") } - - conversationCollectionView.insertItemsAtIndexPaths(indexPaths) } + conversationCollectionView.insertItemsAtIndexPaths(indexPaths) + } else { println("self message") - conversationCollectionView.reloadData() + + var indexPaths = [NSIndexPath]() + + for i in 0.. conversationCollectionView.frame.size.height) { // println("New Message scroll") - UIView.animateWithDuration(0.2, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in + UIView.animateWithDuration(0.2, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { [unowned self] in if (useableSpace > 0) { let contentToScroll = newMessagesTotalHeight - useableSpace @@ -1139,7 +1143,7 @@ class ConversationViewController: BaseViewController { conversationCollectionViewContentOffsetBeforeKeyboardWillShow = conversationCollectionView.contentOffset } - UIView.animateWithDuration(animationDuration, delay: 0, options: UIViewAnimationOptions(animationCurveValue << 16), animations: { () -> Void in + UIView.animateWithDuration(animationDuration, delay: 0, options: UIViewAnimationOptions(animationCurveValue << 16), animations: { [unowned self] in self.messageToolbarBottomConstraint.constant = newHeight @@ -1179,7 +1183,7 @@ class ConversationViewController: BaseViewController { self.view.layoutIfNeeded() - }, completion: { (finished) -> Void in + }, completion: { [unowned self] finished in if keyboard { self.keyboardShowTimes -= 1 } @@ -1206,7 +1210,7 @@ class ConversationViewController: BaseViewController { conversationCollectionViewContentOffsetBeforeKeyboardWillHide = conversationCollectionView.contentOffset } - UIView.animateWithDuration(animationDuration, delay: 0, options: UIViewAnimationOptions(animationCurveValue << 16), animations: { () -> Void in + UIView.animateWithDuration(animationDuration, delay: 0, options: UIViewAnimationOptions(animationCurveValue << 16), animations: { [unowned self] in var contentOffset = self.conversationCollectionViewContentOffsetBeforeKeyboardWillHide @@ -1225,7 +1229,7 @@ class ConversationViewController: BaseViewController { self.view.layoutIfNeeded() - }, completion: { (finished) -> Void in + }, completion: { _ in }) } @@ -1401,14 +1405,14 @@ class ConversationViewController: BaseViewController { let nvc = segue.destinationViewController as! UINavigationController let vc = nvc.topViewController as! PickLocationViewController - vc.sendLocationAction = { coordinate in + vc.sendLocationAction = { [unowned self] coordinate in if let withFriend = self.conversation.withFriend { sendLocationWithCoordinate(coordinate, toRecipient: withFriend.userID, recipientType: "User", afterCreatedMessage: { message in dispatch_async(dispatch_get_main_queue()) { - self.updateConversationCollectionViewWithMessageIDs(nil, scrollToBottom: true, success: { success in + self.updateConversationCollectionViewWithMessageIDs(nil, scrollToBottom: true, success: { _ in }) } @@ -1424,7 +1428,7 @@ class ConversationViewController: BaseViewController { sendLocationWithCoordinate(coordinate, toRecipient: withGroup.groupID, recipientType: "Circle", afterCreatedMessage: { message in dispatch_async(dispatch_get_main_queue()) { - self.updateConversationCollectionViewWithMessageIDs(nil, scrollToBottom: true, success: { success in + self.updateConversationCollectionViewWithMessageIDs(nil, scrollToBottom: true, success: { _ in }) } @@ -1506,7 +1510,7 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi case MessageMediaType.Image.rawValue: let cell = collectionView.dequeueReusableCellWithReuseIdentifier(chatLeftImageCellIdentifier, forIndexPath: indexPath) as! ChatLeftImageCell - cell.configureWithMessage(message, messageImagePreferredWidth: messageImagePreferredWidth, messageImagePreferredHeight: messageImagePreferredHeight, messageImagePreferredAspectRatio: messageImagePreferredAspectRatio, mediaTapAction: { + cell.configureWithMessage(message, messageImagePreferredWidth: messageImagePreferredWidth, messageImagePreferredHeight: messageImagePreferredHeight, messageImagePreferredAspectRatio: messageImagePreferredAspectRatio, mediaTapAction: { [unowned self] in self.performSegueWithIdentifier("showMessageMedia", sender: message) @@ -1519,7 +1523,7 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi let audioPlayedDuration = audioPlayedDurationOfMessage(message) - cell.configureWithMessage(message, audioPlayedDuration: audioPlayedDuration, audioBubbleTapAction: { message in + cell.configureWithMessage(message, audioPlayedDuration: audioPlayedDuration, audioBubbleTapAction: { [unowned self] message in self.playMessageAudioWithMessage(message) @@ -1530,7 +1534,7 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi case MessageMediaType.Video.rawValue: let cell = collectionView.dequeueReusableCellWithReuseIdentifier(chatLeftVideoCellIdentifier, forIndexPath: indexPath) as! ChatLeftVideoCell - cell.configureWithMessage(message, messageImagePreferredWidth: messageImagePreferredWidth, messageImagePreferredHeight: messageImagePreferredHeight, messageImagePreferredAspectRatio: messageImagePreferredAspectRatio, mediaTapAction: { + cell.configureWithMessage(message, messageImagePreferredWidth: messageImagePreferredWidth, messageImagePreferredHeight: messageImagePreferredHeight, messageImagePreferredAspectRatio: messageImagePreferredAspectRatio, mediaTapAction: { [unowned self] in self.performSegueWithIdentifier("showMessageMedia", sender: message) @@ -1541,7 +1545,7 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi case MessageMediaType.Location.rawValue: let cell = collectionView.dequeueReusableCellWithReuseIdentifier(chatLeftLocationCellIdentifier, forIndexPath: indexPath) as! ChatLeftLocationCell - cell.configureWithMessage(message, mediaTapAction: { + cell.configureWithMessage(message, mediaTapAction: { [unowned self] in if let coordinate = message.coordinate { let locationCoordinate = CLLocationCoordinate2D(latitude: coordinate.latitude, longitude: coordinate.longitude) let mapItem = MKMapItem(placemark: MKPlacemark(coordinate: locationCoordinate, addressDictionary: nil)) @@ -1570,7 +1574,7 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi case MessageMediaType.Image.rawValue: let cell = collectionView.dequeueReusableCellWithReuseIdentifier(chatRightImageCellIdentifier, forIndexPath: indexPath) as! ChatRightImageCell - cell.configureWithMessage(message, messageImagePreferredWidth: messageImagePreferredWidth, messageImagePreferredHeight: messageImagePreferredHeight, messageImagePreferredAspectRatio: messageImagePreferredAspectRatio, mediaTapAction: { + cell.configureWithMessage(message, messageImagePreferredWidth: messageImagePreferredWidth, messageImagePreferredHeight: messageImagePreferredHeight, messageImagePreferredAspectRatio: messageImagePreferredAspectRatio, mediaTapAction: { [unowned self] in if message.sendState == MessageSendState.Failed.rawValue { @@ -1600,7 +1604,7 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi let audioPlayedDuration = audioPlayedDurationOfMessage(message) - cell.configureWithMessage(message, audioPlayedDuration: audioPlayedDuration, audioBubbleTapAction: { message in + cell.configureWithMessage(message, audioPlayedDuration: audioPlayedDuration, audioBubbleTapAction: { [unowned self] message in if let message = message { if message.sendState == MessageSendState.Failed.rawValue { @@ -1631,7 +1635,7 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi case MessageMediaType.Video.rawValue: let cell = collectionView.dequeueReusableCellWithReuseIdentifier(chatRightVideoCellIdentifier, forIndexPath: indexPath) as! ChatRightVideoCell - cell.configureWithMessage(message, messageImagePreferredWidth: messageImagePreferredWidth, messageImagePreferredHeight: messageImagePreferredHeight, messageImagePreferredAspectRatio: messageImagePreferredAspectRatio, mediaTapAction: { + cell.configureWithMessage(message, messageImagePreferredWidth: messageImagePreferredWidth, messageImagePreferredHeight: messageImagePreferredHeight, messageImagePreferredAspectRatio: messageImagePreferredAspectRatio, mediaTapAction: { [unowned self] in if message.sendState == MessageSendState.Failed.rawValue { @@ -1659,7 +1663,7 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi case MessageMediaType.Location.rawValue: let cell = collectionView.dequeueReusableCellWithReuseIdentifier(chatRightLocationCellIdentifier, forIndexPath: indexPath) as! ChatRightLocationCell - cell.configureWithMessage(message, mediaTapAction: { + cell.configureWithMessage(message, mediaTapAction: { [unowned self] in if message.sendState == MessageSendState.Failed.rawValue { @@ -1695,7 +1699,7 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi default: let cell = collectionView.dequeueReusableCellWithReuseIdentifier(chatRightTextCellIdentifier, forIndexPath: indexPath) as! ChatRightTextCell - cell.configureWithMessage(message, textContentLabelWidth: textContentLabelWidthOfMessage(message), mediaTapAction: { + cell.configureWithMessage(message, textContentLabelWidth: textContentLabelWidthOfMessage(message), mediaTapAction: { [unowned self] in if message.sendState == MessageSendState.Failed.rawValue { @@ -1809,7 +1813,7 @@ extension ConversationViewController: PullToRefreshViewDelegate { func pulllToRefreshViewDidRefresh(pulllToRefreshView: PullToRefreshView) { delay(1) { - pulllToRefreshView.endRefreshingAndDoFurtherAction() { + pulllToRefreshView.endRefreshingAndDoFurtherAction() { [unowned self] in let lastDisplayedMessagesRange = self.displayedMessagesRange @@ -1957,7 +1961,7 @@ extension ConversationViewController: UIImagePickerControllerDelegate, UINavigat if let withFriend = conversation.withFriend { - sendImageInFilePath(nil, orFileData: imageData, metaData: metaData, toRecipient: withFriend.userID, recipientType: "User", afterCreatedMessage: { message -> Void in + sendImageInFilePath(nil, orFileData: imageData, metaData: metaData, toRecipient: withFriend.userID, recipientType: "User", afterCreatedMessage: { [unowned self] message in dispatch_async(dispatch_get_main_queue()) { @@ -1973,7 +1977,7 @@ extension ConversationViewController: UIImagePickerControllerDelegate, UINavigat } } - self.updateConversationCollectionViewWithMessageIDs(nil, scrollToBottom: true, success: { success in + self.updateConversationCollectionViewWithMessageIDs(nil, scrollToBottom: true, success: { _ in }) } @@ -1986,7 +1990,7 @@ extension ConversationViewController: UIImagePickerControllerDelegate, UINavigat }) } else if let withGroup = conversation.withGroup { - sendImageInFilePath(nil, orFileData: imageData, metaData: nil, toRecipient: withGroup.groupID, recipientType: "Circle", afterCreatedMessage: { message -> Void in + sendImageInFilePath(nil, orFileData: imageData, metaData: nil, toRecipient: withGroup.groupID, recipientType: "Circle", afterCreatedMessage: { [unowned self] message in dispatch_async(dispatch_get_main_queue()) { if let messageImageURL = NSFileManager.saveMessageImageData(imageData, withName: messageImageName) { @@ -2001,7 +2005,7 @@ extension ConversationViewController: UIImagePickerControllerDelegate, UINavigat } } - self.updateConversationCollectionViewWithMessageIDs(nil, scrollToBottom: true, success: { success in + self.updateConversationCollectionViewWithMessageIDs(nil, scrollToBottom: true, success: { _ in }) } @@ -2036,7 +2040,7 @@ extension ConversationViewController: UIImagePickerControllerDelegate, UINavigat let messageVideoName = NSUUID().UUIDString - let afterCreatedMessageAction = { (message: Message) in + let afterCreatedMessageAction = { [unowned self] (message: Message) in dispatch_async(dispatch_get_main_queue()) { if let videoData = NSData(contentsOfURL: videoURL) { @@ -2061,27 +2065,27 @@ extension ConversationViewController: UIImagePickerControllerDelegate, UINavigat } } - self.updateConversationCollectionViewWithMessageIDs(nil, scrollToBottom: true, success: { success in + self.updateConversationCollectionViewWithMessageIDs(nil, scrollToBottom: true, success: { _ in }) } } } if let withFriend = conversation.withFriend { - sendVideoInFilePath(videoURL.path!, orFileData: nil, metaData: metaData, toRecipient: withFriend.userID, recipientType: "User", afterCreatedMessage: afterCreatedMessageAction, failureHandler: {(reason, errorMessage) -> () in + sendVideoInFilePath(videoURL.path!, orFileData: nil, metaData: metaData, toRecipient: withFriend.userID, recipientType: "User", afterCreatedMessage: afterCreatedMessageAction, failureHandler: { (reason, errorMessage) in defaultFailureHandler(reason, errorMessage) // TODO: sendVideo 错误提醒 - }, completion: { success -> Void in + }, completion: { success in println("sendVideo to friend: \(success)") }) } else if let withGroup = conversation.withGroup { - sendVideoInFilePath(videoURL.path!, orFileData: nil, metaData: nil, toRecipient: withGroup.groupID, recipientType: "Circle", afterCreatedMessage: afterCreatedMessageAction, failureHandler: {(reason, errorMessage) -> () in + sendVideoInFilePath(videoURL.path!, orFileData: nil, metaData: nil, toRecipient: withGroup.groupID, recipientType: "Circle", afterCreatedMessage: afterCreatedMessageAction, failureHandler: { (reason, errorMessage) in defaultFailureHandler(reason, errorMessage) // TODO: sendVideo 错误提醒 - }, completion: { success -> Void in + }, completion: { success in println("sendVideo to group: \(success)") }) } diff --git a/Yep/ViewControllers/Conversations/ConversationsViewController.swift b/Yep/ViewControllers/Conversations/ConversationsViewController.swift index ad5a35d9..b2edab2c 100644 --- a/Yep/ViewControllers/Conversations/ConversationsViewController.swift +++ b/Yep/ViewControllers/Conversations/ConversationsViewController.swift @@ -51,11 +51,11 @@ class ConversationsViewController: UIViewController { NSNotificationCenter.defaultCenter().addObserver(self, selector: "reloadConversationsTableView", name: YepNewMessagesReceivedNotification, object: nil) - YepUserDefaults.nickname.bindListener("ConversationsViewController.Nickname") { _ in + YepUserDefaults.nickname.bindListener("ConversationsViewController.Nickname") { [unowned self] _ in self.reloadConversationsTableView() } - YepUserDefaults.avatarURLString.bindListener("ConversationsViewController.Avatar") { _ in + YepUserDefaults.avatarURLString.bindListener("ConversationsViewController.Avatar") { [unowned self] _ in self.reloadConversationsTableView() } diff --git a/Yep/ViewControllers/EditProfile/EditProfileViewController.swift b/Yep/ViewControllers/EditProfile/EditProfileViewController.swift index 09ad18d1..970bd836 100644 --- a/Yep/ViewControllers/EditProfile/EditProfileViewController.swift +++ b/Yep/ViewControllers/EditProfile/EditProfileViewController.swift @@ -154,7 +154,7 @@ extension EditProfileViewController: UITableViewDataSource, UITableViewDelegate cell.annotationLabel.text = NSLocalizedString("Nickname", comment: "") - YepUserDefaults.nickname.bindAndFireListener("EditProfileLessInfoCell.Nickname") { nickname in + YepUserDefaults.nickname.bindAndFireListener("EditProfileLessInfoCell.Nickname") { [unowned self] nickname in cell.infoLabel.text = nickname } @@ -165,7 +165,7 @@ extension EditProfileViewController: UITableViewDataSource, UITableViewDelegate cell.annotationLabel.text = NSLocalizedString("Introduction", comment: "") - YepUserDefaults.introduction.bindAndFireListener("EditProfileLessInfoCell.Introduction") { introduction in + YepUserDefaults.introduction.bindAndFireListener("EditProfileLessInfoCell.Introduction") { [unowned self] introduction in cell.infoLabel.text = introduction } diff --git a/Yep/ViewControllers/Profile/ProfileViewController.swift b/Yep/ViewControllers/Profile/ProfileViewController.swift index 62ec8a97..8bcde3e6 100644 --- a/Yep/ViewControllers/Profile/ProfileViewController.swift +++ b/Yep/ViewControllers/Profile/ProfileViewController.swift @@ -191,7 +191,7 @@ class ProfileViewController: UIViewController { } if user.friendState == UserFriendState.Me.rawValue { - YepUserDefaults.introduction.bindListener("Profile.introductionText") { introduction in + YepUserDefaults.introduction.bindListener("Profile.introductionText") { [unowned self] introduction in if let introduction = introduction { self.introductionText = introduction self.updateProfileCollectionView() @@ -358,7 +358,7 @@ class ProfileViewController: UIViewController { customNavigationItem.title = user.nickname if user.friendState == UserFriendState.Me.rawValue { - YepUserDefaults.nickname.bindListener("ProfileViewController.Title") { nickname in + YepUserDefaults.nickname.bindListener("ProfileViewController.Title") { [unowned self] nickname in self.customNavigationItem.title = nickname } } diff --git a/Yep/Views/Cells/ProfileHeader/ProfileHeaderCell.swift b/Yep/Views/Cells/ProfileHeader/ProfileHeaderCell.swift index f051984c..fe0f4876 100644 --- a/Yep/Views/Cells/ProfileHeader/ProfileHeaderCell.swift +++ b/Yep/Views/Cells/ProfileHeader/ProfileHeaderCell.swift @@ -59,7 +59,7 @@ class ProfileHeaderCell: UICollectionViewCell { updateAvatarWithAvatarURLString(user.avatarURLString) if user.friendState == UserFriendState.Me.rawValue { - YepUserDefaults.avatarURLString.bindListener("ProfileHeaderCell.Avatar") { avatarURLString in + YepUserDefaults.avatarURLString.bindListener("ProfileHeaderCell.Avatar") { [unowned self] avatarURLString in if let avatarURLString = avatarURLString { self.updateAvatarWithAvatarURLString(avatarURLString) } diff --git a/Yep/Views/Cells/SettingsUser/SettingsUserCell.swift b/Yep/Views/Cells/SettingsUser/SettingsUserCell.swift index 26b33790..4cd8ae83 100644 --- a/Yep/Views/Cells/SettingsUser/SettingsUserCell.swift +++ b/Yep/Views/Cells/SettingsUser/SettingsUserCell.swift @@ -30,15 +30,15 @@ class SettingsUserCell: UITableViewCell { let avatarSize = YepConfig.Settings.userCellAvatarSize avatarImageViewWidthConstraint.constant = avatarSize - YepUserDefaults.avatarURLString.bindAndFireListener("SettingsUserCell.Avatar") { _ in + YepUserDefaults.avatarURLString.bindAndFireListener("SettingsUserCell.Avatar") { [unowned self] _ in self.updateAvatar() } - YepUserDefaults.nickname.bindAndFireListener("SettingsUserCell.Nickname") { nickname in + YepUserDefaults.nickname.bindAndFireListener("SettingsUserCell.Nickname") { [unowned self] nickname in self.nameLabel.text = nickname } - YepUserDefaults.introduction.bindAndFireListener("SettingsUserCell.Introduction") { introduction in + YepUserDefaults.introduction.bindAndFireListener("SettingsUserCell.Introduction") { [unowned self] introduction in self.introLabel.text = introduction }