Skip to content
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

manager.whenSelected not work #34

Closed
andrewSvsg opened this issue Mar 21, 2016 · 22 comments
Closed

manager.whenSelected not work #34

andrewSvsg opened this issue Mar 21, 2016 · 22 comments

Comments

@andrewSvsg
Copy link

I use my custom cell class LabelCell in storyboard
This is setup method

func setupTable() {
    manager.startManagingWithDelegate(self)
    manager.registerCellClass(ParamValueCell.self)
    manager.whenSelected(ParamValueCell.self){ postCell, post, indexPath in
      print("Selected \(post) in \(postCell) at \(indexPath)")
    }
  }

I fill cells and they appear in table
but "manager.whenSelected" not work and
print("Selected \(post) in \(postCell) at \(indexPath)") - never called

In debug seems that fail in next place

func reactionsOfType(type: UIReactionType, forView view: Any) -> [UIReaction] {
    ....
    //fail in this place
    reaction.viewClass == unwrappedView.dynamicType.
    ...
}

My cell class
public struct LabelCellModel {  
  let labelValue: Variable<String>
}

public class LabelCell: TableViewCell, ModelTransfer {

  @IBOutlet weak var label: UILabel!

  public func updateWithModel(model: LabelCellModel) {

    model.labelValue.asObservable()
      .takeUntil(rx_reuse)
      .subscribeNext({[weak self] labelText in self?.label.text = labelText })
      .addDisposableTo(disposeBag)
  }
}
@DenTelezhkin
Copy link
Owner

Do you call registerCellClass method for LabelCell? You have two different types of cells, ParamValueCell and LabelCell.

@DenTelezhkin DenTelezhkin self-assigned this Mar 21, 2016
@andrewSvsg
Copy link
Author

Sorry I copied method from another controller
this is actual version

func setupTable() {
    manager.startManagingWithDelegate(self)
    manager.registerCellClass(LabelCell.self)
    manager.whenSelected(LabelCell.self){ postCell, post, indexPath in
      print("Selected \(post) in \(postCell) at \(indexPath)")
}

LabelCell registered with manager

@DenTelezhkin
Copy link
Owner

What version of DTTableViewManager are you using? In my projects and unit tests whenSelected seems to work fine.

@andrewSvsg
Copy link
Author

This records form Podfile.lock

  • DTCollectionViewManager (4.5.2):
    • DTModelStorage (~> 2.4.0)
  • DTModelStorage (2.4.3):
    • DTModelStorage/Core (= 2.4.3)
  • DTModelStorage/Core (2.4.3)
  • DTTableViewManager (4.5.3):
    • DTModelStorage (~> 2.4.0)

@DenTelezhkin
Copy link
Owner

Hmm, interesting. Do you have only one cell, or maybe you have some subclasses also registered?

It would be great if you printed those

//fail in this place
    reaction.viewClass == unwrappedView.dynamicType

What are values for these variables?

@andrewSvsg
Copy link
Author

print("reaction.reactionType=\(reaction.reactionType)")
print("type=\(type)")
print("reaction.viewClass=\(reaction.viewClass)")
print("unwrappedView.dynamicType=\(unwrappedView.dynamicType)")
return reaction.reactionType == type && reaction.viewClass == unwrappedView.dynamicType

output:
reaction.reactionType=CellSelection
type=CellSelection
reaction.viewClass=LabelCell
unwrappedView.dynamicType=LabelCell

@andrewSvsg
Copy link
Author

I add to return value

            print("reaction.reactionType=\(reaction.reactionType)")
            print("type=\(type)")
            print("reaction.viewClass=\(reaction.viewClass)")
            print("unwrappedView.dynamicType=\(unwrappedView.dynamicType)")

            print("\(reaction.reactionType == type && reaction.viewClass == unwrappedView.dynamicType)")

            return reaction.reactionType == type && reaction.viewClass == unwrappedView.dynamicType

reaction.reactionType=CellSelection
type=CellSelection
reaction.viewClass=LabelCell
unwrappedView.dynamicType=LabelCell
false

@DenTelezhkin
Copy link
Owner

Wow. So, reaction.viewClass == unwrappedView.dynamicType is failing? That's super weird. The only crazy idea i have right now is maybe you have overloaded comparisons between types?

@andrewSvsg
Copy link
Author

Or I have 2 LabelCell classes in project ( and they mixed in runtime

@andrewSvsg
Copy link
Author

I can not understand this problem
This works
return reaction.reactionType == type && String(reaction.viewClass) == String(unwrappedView.dynamicType)

but maybe it a source of other issues

@DenTelezhkin
Copy link
Owner

I think I agree to compare String representations of those variables, however this case needs to be reproduced in our test suite, so we had protection against other issues in the future.

Can i ask you to reproduce this behaviour in unit tests in DTModelStorage?
https://github.com/DenHeadless/DTModelStorage/blob/master/DTModelStorageTests/XCTests/Specs/UIReactionsTestCase.swift

@DenTelezhkin
Copy link
Owner

Closing due to inactivity, please feel free to reopen if you have any additional information.

@orkenstein
Copy link

Hit the same issue. How to reproduce this?

@DenTelezhkin
Copy link
Owner

I have no idea, never managed to reproduce this behavior. Were you able to reproduce while debugging in Xcode?

If yes, what versions of Xcode, Swift, and DTTableViewManager are you using?

@orkenstein
Copy link

Xcode 7.3.1
Swift 2.2
DTCollectionViewManager (4.5.2)
DTModelStorage (2.4.4)
DTTableViewManager (4.5.3)

Just to add some more weirdness. It works under one target, and does not under another. Console output:

Staging:
po reaction.viewClass == unwrappedView.dynamicType
false
po reaction.viewClass
PavemintStaging.ConversationCell
po unwrappedView.dynamicType
PavemintStaging.ConversationCell

Second:
po reaction.viewClass == unwrappedView.dynamicType
true
po reaction.viewClass
PavemintLocal.ConversationCell
po unwrappedView.dynamicType
PavemintLocal.ConversationCell

@DenTelezhkin
Copy link
Owner

Swift is insane nowadays))) Maybe connected to Debug/Release configurations.

Can you try using previous solution found in this thread?

return reaction.reactionType == type && String(reaction.viewClass) == String(unwrappedView.dynamicType)

@DenTelezhkin DenTelezhkin reopened this May 24, 2016
@orkenstein
Copy link

Yes, this helps.

DenTelezhkin added a commit to DenTelezhkin/DTModelStorage that referenced this issue May 24, 2016
use Realm in memory to make Realm fine grained notifications tests run correctly
@orkenstein
Copy link

Looks like you've added a commit with this fix. Cool!
Can't wait for a new .pod version.

@DenTelezhkin
Copy link
Owner

I'm actually making release right now =) I'll update this issue when it will be ready.

@orkenstein
Copy link

Cool! Thanks for SWIFT support.

@DenTelezhkin
Copy link
Owner

Aaand finally all releases are live 🍻

DTModelStorage 2.6.0
DTTableViewManager 4.7.0
DTCollectionViewManager 4.7.0

@orkenstein
Copy link

Great! And it works.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants