{"action":"created","issue":{"url":"https://api.github.com/repos/mac-cain13/R.swift/issues/223","repository_url":"https://api.github.com/repos/mac-cain13/R.swift","labels_url":"https://api.github.com/repos/mac-cain13/R.swift/issues/223/labels{/name}","comments_url":"https://api.github.com/repos/mac-cain13/R.swift/issues/223/comments","events_url":"https://api.github.com/repos/mac-cain13/R.swift/issues/223/events","html_url":"https://github.com/mac-cain13/R.swift/issues/223","id":156934783,"number":223,"title":"Additional root objects in a .xib causing reuse identifiers to be lost","user":{"login":"mbernson","id":477710,"avatar_url":"https://avatars.githubusercontent.com/u/477710?v=3","gravatar_id":"","url":"https://api.github.com/users/mbernson","html_url":"https://github.com/mbernson","followers_url":"https://api.github.com/users/mbernson/followers","following_url":"https://api.github.com/users/mbernson/following{/other_user}","gists_url":"https://api.github.com/users/mbernson/gists{/gist_id}","starred_url":"https://api.github.com/users/mbernson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbernson/subscriptions","organizations_url":"https://api.github.com/users/mbernson/orgs","repos_url":"https://api.github.com/users/mbernson/repos","events_url":"https://api.github.com/users/mbernson/events{/privacy}","received_events_url":"https://api.github.com/users/mbernson/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-05-26T08:52:22Z","updated_at":"2016-05-27T10:59:54Z","closed_at":"2016-05-27T10:59:54Z","body":"After adding more root objects (such as a gesture recognizer or custom object) to a .xib, R.swift will not add the reuse identifier to its generated struct anymore.\r\n\r\nI've found two possible fixes. In `Nib.swift`, we could blacklist the objects:\r\n\r\n```diff\r\ndiff --git a/R.swift/ResourceTypes/Nib.swift b/R.swift/ResourceTypes/Nib.swift\r\nindex 609c75d..c30d3b2 100644\r\n--- a/R.swift/ResourceTypes/Nib.swift\r\n+++ b/R.swift/ResourceTypes/Nib.swift\r\n@@ -40,7 +40,10 @@ struct Nib: WhiteListedExtensionsResourceType, ReusableContainer {\r\n }\r\n \r\n private class NibParserDelegate: NSObject, NSXMLParserDelegate {\r\n-  let ignoredRootViewElements = [\"placeholder\"]\r\n+  let ignoredRootViewElements = [\r\n+    \"placeholder\",\r\n+    \"customObject\",\r\n+    \"tapGestureRecognizer\",\r\n+    // ...and many more :(\r\n+  ]\r\n   var rootViews: [Type] = []\r\n   var reusables: [Reusable] = []\r\n```\r\n\r\nOtherwise, we could change or remove [this condition in `NibGenerator.swift`](https://github.com/mac-cain13/R.swift/blob/d49c00dfe93066d5ab61ab7ae92965857c98d60f/R.swift/Generators/NibGenerator.swift#L149):\r\n\r\n```diff\r\ndiff --git a/R.swift/Generators/NibGenerator.swift b/R.swift/Generators/NibGenerator.swift\r\nindex 085c434..d222acb 100644\r\n--- a/R.swift/Generators/NibGenerator.swift\r\n+++ b/R.swift/Generators/NibGenerator.swift\r\n@@ -146,7 +146,7 @@ struct NibGenerator: Generator {\r\n     let reuseIdentifierProperties: [Property]\r\n     let reuseProtocols: [Type]\r\n     let reuseTypealiasses: [Typealias]\r\n-    if let reusable = nib.reusables.first where nib.rootViews.count == 1 && nib.reusables.count == 1 {\r\n+    if let reusable = nib.reusables.first where nib.rootViews.count >= nib.reusables.count {\r\n       reuseIdentifierProperties = [Let(\r\n         isStatic: false,\r\n         name: \"identifier\",\r\n```\r\n\r\nWhat is the desired solution for this?\r\nI'd like to fix this in a PR, but wanted to discuss it first. :)"},"comment":{"url":"https://api.github.com/repos/mac-cain13/R.swift/issues/comments/222119192","html_url":"https://github.com/mac-cain13/R.swift/issues/223#issuecomment-222119192","issue_url":"https://api.github.com/repos/mac-cain13/R.swift/issues/223","id":222119192,"user":{"login":"mbernson","id":477710,"avatar_url":"https://avatars.githubusercontent.com/u/477710?v=3","gravatar_id":"","url":"https://api.github.com/users/mbernson","html_url":"https://github.com/mbernson","followers_url":"https://api.github.com/users/mbernson/followers","following_url":"https://api.github.com/users/mbernson/following{/other_user}","gists_url":"https://api.github.com/users/mbernson/gists{/gist_id}","starred_url":"https://api.github.com/users/mbernson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbernson/subscriptions","organizations_url":"https://api.github.com/users/mbernson/orgs","repos_url":"https://api.github.com/users/mbernson/repos","events_url":"https://api.github.com/users/mbernson/events{/privacy}","received_events_url":"https://api.github.com/users/mbernson/received_events","type":"User","site_admin":false},"created_at":"2016-05-27T10:59:54Z","updated_at":"2016-05-27T10:59:54Z","body":"You are correct. After testing my patch in an actual app, using a collectionviewcell with a gesture recognizer resulted in this exception:\r\n\r\n`Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'invalid nib registered for identifier (myCell) - nib must contain exactly one top level object which must be a UICollectionReusableView instance'`\r\n\r\nRegular xibs are not affected by this, and storyboards (referenced issues) will need a different solution."}}
{"actor":{"display_login":"mbernson"}}