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

Fix ValidIBInspectable rule implementation #901

Merged
merged 1 commit into from
Nov 29, 2016

Conversation

dduan
Copy link
Contributor

@dduan dduan commented Nov 26, 2016

There are several issue in the current implementation of this rule:

  1. NSNumber is not IB-inspectable at all.
  2. Explicitly typed Optionals and ImplicitlyUnwrappedOptionals aren't
    supported by @IBInspectable, reference type or not.
  3. Supported value types with !s and ?s are indeed inspectable, contrary to
    what the current implementation deems.

For verification, try these out with this little class:

https://gist.github.com/dduan/da4050ca3a0bce5b4d54d21effb06b24

@dduan
Copy link
Contributor Author

dduan commented Nov 26, 2016

Would love someone else to verify these. I don't have extensive experience with @IBInspectable other than the tests I ran with Xcode 8.1

@jpsim
Copy link
Collaborator

jpsim commented Nov 26, 2016

I'll defer to @marcelofabri to review this. I'm also not very familiar with @IBInspectable.

@codecov-io
Copy link

codecov-io commented Nov 26, 2016

Current coverage is 86.09% (diff: 100%)

Merging #901 into master will decrease coverage by <.01%

@@             master       #901   diff @@
==========================================
  Files           114        114          
  Lines          5058       5055     -3   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
- Hits           4355       4352     -3   
  Misses          703        703          
  Partials          0          0          

Powered by Codecov. Last update e63c6ce...7d4e0ae

@dduan
Copy link
Contributor Author

dduan commented Nov 26, 2016

Posting the test result from 8.1 here for reference.

demo

@marcelofabri
Copy link
Collaborator

marcelofabri commented Nov 26, 2016

@dduan Thanks for sharing this. It seems that 1 and 2 are indeed correct.

About 3, while Xcode shows the fields in IB, I get errors in runtime:

2016-11-26 10:51:48.609 IBDesignableTests[60404:1521401] Failed to set (intiuo) user defined inspected property on (IBDesignableTests.TestView): [<IBDesignableTests.TestView 0x7fa1da01fe00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key intiuo.
2016-11-26 10:51:48.610 IBDesignableTests[60404:1521401] Failed to set (intoptional) user defined inspected property on (IBDesignableTests.TestView): [<IBDesignableTests.TestView 0x7fa1da01fe00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key intoptional.
2016-11-26 10:51:48.610 IBDesignableTests[60404:1521401] Failed to set (cgfloatiuo) user defined inspected property on (IBDesignableTests.TestView): [<IBDesignableTests.TestView 0x7fa1da01fe00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key cgfloatiuo.
2016-11-26 10:51:48.610 IBDesignableTests[60404:1521401] Failed to set (cgfloatoptional) user defined inspected property on (IBDesignableTests.TestView): [<IBDesignableTests.TestView 0x7fa1da01fe00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key cgfloatoptional.
2016-11-26 10:51:48.610 IBDesignableTests[60404:1521401] Failed to set (floatiuo) user defined inspected property on (IBDesignableTests.TestView): [<IBDesignableTests.TestView 0x7fa1da01fe00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key floatiuo.
2016-11-26 10:51:48.612 IBDesignableTests[60404:1521401] Failed to set (floatoptional) user defined inspected property on (IBDesignableTests.TestView): [<IBDesignableTests.TestView 0x7fa1da01fe00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key floatoptional.
2016-11-26 10:51:48.613 IBDesignableTests[60404:1521401] Failed to set (doubleiuo) user defined inspected property on (IBDesignableTests.TestView): [<IBDesignableTests.TestView 0x7fa1da01fe00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key doubleiuo.
2016-11-26 10:51:48.613 IBDesignableTests[60404:1521401] Failed to set (booliuo) user defined inspected property on (IBDesignableTests.TestView): [<IBDesignableTests.TestView 0x7fa1da01fe00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key booliuo.
2016-11-26 10:51:48.613 IBDesignableTests[60404:1521401] Failed to set (booloptional) user defined inspected property on (IBDesignableTests.TestView): [<IBDesignableTests.TestView 0x7fa1da01fe00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key booloptional.
2016-11-26 10:51:48.629 IBDesignableTests[60404:1521401] Failed to set (doubleoptional) user defined inspected property on (IBDesignableTests.TestView): [<IBDesignableTests.TestView 0x7fa1da01fe00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key doubleoptional.
2016-11-26 10:51:48.630 IBDesignableTests[60404:1521401] Failed to set (cgpointiuo) user defined inspected property on (IBDesignableTests.TestView): [<IBDesignableTests.TestView 0x7fa1da01fe00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key cgpointiuo.
2016-11-26 10:51:48.630 IBDesignableTests[60404:1521401] Failed to set (cgpointoptional) user defined inspected property on (IBDesignableTests.TestView): [<IBDesignableTests.TestView 0x7fa1da01fe00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key cgpointoptional.
2016-11-26 10:51:48.631 IBDesignableTests[60404:1521401] Failed to set (cgsizeiuo) user defined inspected property on (IBDesignableTests.TestView): [<IBDesignableTests.TestView 0x7fa1da01fe00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key cgsizeiuo.
2016-11-26 10:51:48.633 IBDesignableTests[60404:1521401] Failed to set (cgsizeoptional) user defined inspected property on (IBDesignableTests.TestView): [<IBDesignableTests.TestView 0x7fa1da01fe00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key cgsizeoptional.
2016-11-26 10:51:48.634 IBDesignableTests[60404:1521401] Failed to set (cgrectiuo) user defined inspected property on (IBDesignableTests.TestView): [<IBDesignableTests.TestView 0x7fa1da01fe00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key cgrectiuo.
2016-11-26 10:51:48.634 IBDesignableTests[60404:1521401] Failed to set (cgrectoptional) user defined inspected property on (IBDesignableTests.TestView): [<IBDesignableTests.TestView 0x7fa1da01fe00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key cgrectoptional.

Can you reproduce that? I had to remove all the privates (it was easier than adding dynamic or @objc) so the properties are available to setValue:forKey:).

Also, this needs a rebase because I merged another PR (#886) 😬

@dduan
Copy link
Contributor Author

dduan commented Nov 28, 2016

@marcelofabri huh, you are right about the runtime error. So it seems that optionals and IUOs aren't supported at all.

@dduan
Copy link
Contributor Author

dduan commented Nov 28, 2016

@marcelofabri updated with changes only relate to 1 and 2.

@marcelofabri
Copy link
Collaborator

@dduan Thanks for this 🎉

Could you also please add a CHANGELOG entry to give yourself credit? You can see the expected format here.

@dduan
Copy link
Contributor Author

dduan commented Nov 28, 2016

@marcelofabri added entry to CHANGLOG. Thanks for reviewing!

@@ -45,6 +45,9 @@

##### Bug Fixes

* Rule out a few invalid `@IBInspectable` cases in `valid_ibinspectable`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need two trailing spaces after the . 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. This is quite strange. Do you know the reason for it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's to force markdown to add a <br/>. From the original spec:

When you do want to insert a <br /> break tag using Markdown, you end a line with two or more spaces, then type return.

1. `NSNumber` is not IB-inspectable at all.
2. Explicitly typed `Optional`s and `ImplicitlyUnwrappedOptional`s aren't
   supported by `@IBInspectable`, reference type or not.
Copy link
Collaborator

@marcelofabri marcelofabri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just wait Travis to merge ✅

Thanks again for bringing this up 🎉

@jpsim jpsim merged commit 60852d7 into realm:master Nov 29, 2016
@jpsim
Copy link
Collaborator

jpsim commented Nov 29, 2016

Many thanks to both of you!

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

Successfully merging this pull request may close these issues.

None yet

4 participants