-
Notifications
You must be signed in to change notification settings - Fork 143
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
Objective C Storyboard swizzling #46
Conversation
Sources/Storyboard+Swizzling.m
Outdated
if (self == [Storyboard class]) { | ||
|
||
// Instantiate SwinjectStoryboard if UI/NSStoryboard is trying to be instantiated. | ||
if [SwinjectStoryboard isCreatingStoryboardReference] { |
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.
Need to #import "SwinjectStoryboard-Swift.h"
in order to access this Swift class method, but for some reason the header is not automatically generated.
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.
@mpdifran, I'll reply shortly.
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.
Hi @mpdifran. I took time for my misunderstanding.
Usually a bridging header is required to access objc classes or methods from Swift. If you need to expose Swift class, you can just add @objc
annotation. If the problem is that isCreatingStoryboardReference
is defined as static var
, you can change it to class var
.
Am I missing the point of your comment?
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.
You're right, the bridging header is for accessing ObjC classes in Swift, but in this case, we're accessing a Swift class in ObjC. From what I've read online, there should be an automatically generated header named SwinjectStoryboard-Swift.h
that we can import in our ObjC files.
But maybe adding the @objc
to the class and changing the static var
to a class var
will work. I'll give that a shot.
Updated to use
|
38fbbe2
to
4fd7f18
Compare
@mpdifran, I reproduced the issue. As you said, we needed to import |
I followed the section below in the Apple's official document, but still
|
Sources/Storyboard+Swizzling.m
Outdated
|
||
#import "Storyboard+Swizzling.h" | ||
#import <objc/runtime.h> | ||
#import <SwinjectStoryboard/SwinjectStoryboard-Swift.h> |
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.
This seems to be the correct way to import the header.
I'm still getting one warning on |
@mpdifran, I'm sorry I took time to respond. Do you have any change since the last week? I will fetch your commit to check the warning on |
Nope, haven't taken a look at it since. |
@mpdifran Do you no longer have the error to import the header file? I still have error here in
|
Ah looks like I hadn't pushed up my recent changes. I just did a force push, try pulling down the branch again. Also, correct, I am able to build the project fine; I don't see the header error. |
@@ -26,7 +26,7 @@ class Container_SwinjectStoryboardSpec: QuickSpec { | |||
expect(container.description) == | |||
"[\n" | |||
+ " { Service: \(controllerType), Storyboard: SwinjectStoryboardTests.AnimalViewController, " | |||
+ "Factory: ((Resolver, \(controllerType))) -> \(controllerType), ObjectScope: graph, InitCompleted: Specified }\n" | |||
+ "Factory: (Resolver, \(controllerType)) -> \(controllerType), ObjectScope: graph, InitCompleted: Specified }\n" |
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.
Not sure why, but this test was failing, and I needed to make this change in order to make it pass.
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.
It's difference between Swift 3.0 and 3.1. Swift 3.1 fixed the doubly printed tuple: ((a, b))
Swinject/Swinject#252
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.
Ah ok cool.
Thanks @mpdifran👍 I confirmed the build passed with the swift header imported. I'm going to check the issue on |
I'll investigate |
Just did a rebase and force push to fix the merge conflicts. @yoichitgy I'll be around this weekend if you want some help tackling this. |
I think I've fixed the last warning. Let me know if you approve of this implementation. |
Looks like the tests are failing. I'll take another look sometime soon. |
Fixed the failing test. Moved the |
bundle storyboardBundleOrNil: Bundle?) -> SwinjectStoryboard { | ||
return SwinjectStoryboard.create(name: name, bundle: storyboardBundleOrNil, | ||
container: SwinjectStoryboard.defaultContainer) | ||
} |
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.
This needed to be done because ObjC doesn't support Swift's default parameters (container: Resolver = SwinjectStoryboard.defaultContainer
). These two methods are functionally equivalent to the single old method, so the API hasn't actually changed.
I'm sorry, but I'll continue working on Podspec in a few days 🙇 |
@yoichitgy do you think you'll have a chance to fix the pod spec soon? |
Sorry @mpdifran for my late response for this valuable pull request😱 I was too busy for a big project as my job to work on Swinject projects, but I got knowledge about podspec a lot in the project. I will try to solve the problem within a few weeks🏃 |
@mpdifran, I resolved the following issue on
Now I got new errors:
I'm working on the issues now. |
The cause of the new errors is this:
|
…thod to Objective-C. I actually want to revert this commit not to make the property and method public because they are not intended to be used by users of SwinjectStoryboard.
I solved the @mpdifran, do you have any idea to revert the commit and solve the problem by another way? (I made a pull request to merge my changes into your pull request.) |
…version of CocoaPods.
Let me take a look at it when I get a chance. Was this issue introduced due to the |
I'm still not sure the cause of the problem that I didn't get the problem when I built SwinjectStoryboard project, but it might be reproducible if you install SwinjectStoryboard to an app project by Carthage. (I didn't try this yet.) |
I'm currently using this branch in one of my apps through Carthage, so there's no problem on the Carthage side. |
Thanks @mpdifran👍 I'll investigate podspec to make those method |
I'm trying to resolve the issue by fixing directions of Swift/ObjC references. |
…enced method to Objective-C." This reverts commit e5d2043.
# Conflicts: # Sources/SwinjectStoryboardProtocol.swift
@mpdifran, I made PR #67 taking over your PR to fix the installation issue. Your PR will be automatically merged when #67 is merged. At the end, I ended up with Thank you for your investigation, fix and patience😃😃😃 |
Update of your pull request Swinject#46 to Swinject/SwinjectStoryboard
Thanks @mpdifran for merging my branch👍 |
DO NOT MERGE: work in progress.
EDIT: It is now ready for merge once we update TravisCI.