Skip to content

Conversation

VatoKo
Copy link
Contributor

@VatoKo VatoKo commented Jun 4, 2020

Checklist

  • I checked the Contributing Guidelines before creating this request.
  • New extensions are written in Swift 5.0.
  • New extensions support iOS 10.0+ / tvOS 9.0+ / macOS 10.10+ / watchOS 2.0+, or use @available if not.
  • I have added tests for new extensions, and they passed.
  • All extensions have a clear comments explaining their functionality, all parameters and return type in English.
  • All extensions are declared as public.
  • I have added a changelog entry describing my changes.

@VatoKo
Copy link
Contributor Author

VatoKo commented Jun 4, 2020

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.

@VatoKo VatoKo closed this Jun 4, 2020
Copy link
Contributor

@guykogus guykogus left a 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?

@VatoKo
Copy link
Contributor Author

VatoKo commented Jun 4, 2020

Okay, I'll try. Thanks 😊

@VatoKo VatoKo reopened this Jun 4, 2020
@VatoKo
Copy link
Contributor Author

VatoKo commented Jun 4, 2020

@guykogus I updated the code the way you suggested. Besides, how would you unit test this code?

Copy link
Contributor

@guykogus guykogus left a 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.

@LucianoPAlmeida
Copy link
Member

@VatoKo There are a couple of swiftlint issues which needs to be addressed

@codecov
Copy link

codecov bot commented Jun 8, 2020

Codecov Report

Merging #860 into master will decrease coverage by 0.02%.
The diff coverage is 83.33%.

Impacted file tree graph

@@            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     
Flag Coverage Δ
#ios 95.58% <83.33%> (-0.03%) ⬇️
#macos 97.08% <ø> (ø)
#tvos 93.56% <83.33%> (-0.02%) ⬇️
Impacted Files Coverage Δ
...wifterSwift/UIKit/UIViewControllerExtensions.swift 95.91% <83.33%> (-1.76%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 02f65f5...7fdbbe0. Read the comment docs.

@LucianoPAlmeida
Copy link
Member

Closing due inactivity, @VatoKo feel free to reopen if you still want to move this forward :)

@VatoKo
Copy link
Contributor Author

VatoKo commented Jul 1, 2020

@LucianoPAlmeida I was waiting for the final decision from you actually 😄I'll make changes according to the way you suggested.

@VatoKo VatoKo reopened this Jul 1, 2020
Copy link
Contributor

@guykogus guykogus left a 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.

@guykogus
Copy link
Contributor

guykogus commented Jul 1, 2020

@guykogus I get "Could not find a storyboard named 'TestStoryboard' in bundle..." error on unit test. I checked already existing unit test where this storyboard is used and those tests are failing too. Any idea what could be causing this?

I'm not really sure. It may be to do with catalyst. You may need to add #if !targetEnvironment(macCatalyst). Give it a try.
Also, make sure that you're open the project in Xcode via the SwifterSwift.xcworkspace file in Finder. If you try to open the project directly from Xcode it will open it as a Swift package, which doesn't support resources (until Xcode 12).

@VatoKo
Copy link
Contributor Author

VatoKo commented Jul 1, 2020

@guykogus I've always opened the project via SwifterSwift.xcworkspace, no problem with that. Tried #if !targetEnvironment(macCatalyst) check and it's still failing as you can see. 😕

guykogus
guykogus previously approved these changes Jul 1, 2020
LucianoPAlmeida
LucianoPAlmeida previously approved these changes Jul 1, 2020
@LucianoPAlmeida
Copy link
Member

We have a problem with the build

Tests/UIKitTests/UIViewControllerExtensionsTests.swift#L59: use of unresolved identifier ‘MyViewController’ 
let myViewController = MyViewController.instantiate(from: "TestStoryboard", bundle: Bundle(for: UIViewControllerExtensionsTests.self))

@guykogus
Copy link
Contributor

guykogus commented Jul 2, 2020

We have a problem with the build

Tests/UIKitTests/UIViewControllerExtensionsTests.swift#L59: use of unresolved identifier ‘MyViewController’ 
let myViewController = MyViewController.instantiate(from: "TestStoryboard", bundle: Bundle(for: UIViewControllerExtensionsTests.self))

Do you have any more context for this error?

@LucianoPAlmeida
Copy link
Member

Nope, I just copied what danger is saying :)

@VatoKo
Copy link
Contributor Author

VatoKo commented Jul 2, 2020

I don't have such problem. The code compiles and even passes the test successfully.

@LucianoPAlmeida
Copy link
Member

Ok I'll take a look ASAP :)

@SwifterSwift SwifterSwift deleted a comment from SwifterSwiftBot Jul 3, 2020
@SwifterSwiftBot
Copy link

SwifterSwiftBot commented Jul 3, 2020

4 Messages
📖 Thank you for submitting a pull request to SwifterSwift. The team will review your submission as soon as possible.
📖 iOS: Executed 680 tests, with 0 failures (0 unexpected) in 22.793 (24.513) seconds
📖 tvOS: Executed 645 tests, with 0 failures (0 unexpected) in 3.711 (4.152) seconds
📖 macOS: Executed 511 tests, with 0 failures (0 unexpected) in 6.251 (6.489) seconds

Generated by 🚫 Danger

@guykogus guykogus dismissed stale reviews from LucianoPAlmeida and themself via 7fdbbe0 July 3, 2020 14:15
@guykogus
Copy link
Contributor

guykogus commented Jul 3, 2020

@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.

@VatoKo
Copy link
Contributor Author

VatoKo commented Jul 3, 2020

@guykogus I guess I have to say thank you 😄

Copy link
Member

@LucianoPAlmeida LucianoPAlmeida left a comment

Choose a reason for hiding this comment

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

Great

@guykogus guykogus merged commit f75ea86 into SwifterSwift:master Jul 3, 2020
nasircsms pushed a commit to nasircsms/SwifterSwift that referenced this pull request Aug 26, 2020
* '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
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.

4 participants