-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Added new protocol for UIViewController to instantiate it from storyboard #860
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
Added new protocol for UIViewController to instantiate it from storyboard #860
Conversation
Here I thought about making extension to UIViewController directly, but then every time you instantiated a custom UIViewController, you would have to cast it to your type as the return type for the function would be 'UIViewController'. In this way that casting won't be necessary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@VatoKo I have a similar extension that you can use here, without any extra protocol or anything.
public extension UIViewController {
class func newFromStoryboard(storyboardName: String = "Main",
storyboardBundle: Bundle? = nil,
identifier: String? = nil) -> Self {
return UIStoryboard(name: storyboardName, bundle: storyboardBundle)
.instantiateViewController(withIdentifier: identifier ?? String(describing: self)) as! Self // swiftlint:disable:this force_cast
}
}
Why don't you adapt that?
Okay, I'll try. Thanks 😊 |
@guykogus I updated the code the way you suggested. Besides, how would you unit test this code? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to add unit tests and a CHANGELOG entry.
@VatoKo There are a couple of swiftlint issues which needs to be addressed |
Codecov Report
@@ Coverage Diff @@
## master #860 +/- ##
==========================================
- Coverage 95.49% 95.47% -0.03%
==========================================
Files 100 100
Lines 3399 3405 +6
==========================================
+ Hits 3246 3251 +5
- Misses 153 154 +1
Continue to review full report at Codecov.
|
Closing due inactivity, @VatoKo feel free to reopen if you still want to move this forward :) |
@LucianoPAlmeida I was waiting for the final decision from you actually 😄I'll make changes according to the way you suggested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, but left you a few small points.
I'm not really sure. It may be to do with catalyst. You may need to add |
@guykogus I've always opened the project via |
We have a problem with the build
|
Do you have any more context for this error? |
Nope, I just copied what danger is saying :) |
I don't have such problem. The code compiles and even passes the test successfully. |
Ok I'll take a look ASAP :) |
Generated by 🚫 Danger |
@VatoKo I went ahead and fixed it for you. I was actually curious to see if I could push to your fork. I guess I can cos I have superpowers? 😅 The main issue was for the tvOS tests. We needed a separate storyboard for tvOS, since storyboards aren't cross-platform. |
@guykogus I guess I have to say thank you 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great
* 'master' of https://github.com/SwifterSwift/SwifterSwift: (79 commits) Helper functions for scrolling to the edges or by page of a scroll view (SwifterSwift#888) Add XCTest extension for comparing Color objects (SwifterSwift#889) Fix swiftlint error (SwifterSwift#894) Bump kramdown from 2.1.0 to 2.3.0 (SwifterSwift#891) Added note for UIView.addShadow() (SwifterSwift#890) loadFromNib(withClass) (SwifterSwift#885) constraint finders (widthConstraint, heightConstraint, leadingConstraint, trailingConstraint, topConstraint, bottomConstraint) (SwifterSwift#886) added String.regexEscaped (SwifterSwift#883) Make √ generic for FloatingPoint values (SwifterSwift#880) Update UITextField extensions (SwifterSwift#878) Added `masksToBounds` (IBInspectable) extension (SwifterSwift#877) Reinstate debounce function (SwifterSwift#869) `RandomAccessCollection`/`Collection` generalisations (SwifterSwift#863) Added HKActivitySummary extensions (SwifterSwift#875) Added new method for easily instantiating a view controller from a storyboard (SwifterSwift#860) Clean up code (SwifterSwift#864) fixed "".truncated crashed (SwifterSwift#866) Deprecated map(by:), compactMap(by:), filter(by:) (SwifterSwift#862) Overloaded 'contains' operator for string regex matching (SwifterSwift#858) Added convenient wrapper to asyncAfter (SwifterSwift#859) ... # Conflicts: # Sources/SwifterSwift/AppKit/NSColorExtensions.swift # Sources/SwifterSwift/AppKit/NSImageExtensions.swift # Sources/SwifterSwift/AppKit/NSViewExtensions.swift # Sources/SwifterSwift/CoreGraphics/CGColorExtensions.swift # Sources/SwifterSwift/CoreGraphics/CGFloatExtensions.swift # Sources/SwifterSwift/CoreGraphics/CGPointExtensions.swift # Sources/SwifterSwift/CoreGraphics/CGSizeExtensions.swift # Sources/SwifterSwift/Foundation/NSAttributedStringExtensions.swift # Sources/SwifterSwift/SwiftStdlib/StringExtensions.swift # SwifterSwift.xcodeproj/project.pbxproj # Tests/AppKitTests/NSColorExtensionsTests.swift # Tests/SwiftStdlibTests/StringExtensionsTests.swift
Checklist
@available
if not.