I have a fairly complex situation that will be better with help.
This is an iOS app with mixed Swift and Objective - C.
Objective C classes subclass from Objective C classes only.
I have one Swift class named SettingsViewController.swift that extends from a Swift library class called QuickTableViewController. QuickTableViewController is a framework installed via Carthage. https://github.com/bcylin/QuickTableViewController.
After I set this up, I receive a build error when navigating to "Main.storyboard". I can still run the app, but I can't see my IBDesignables in the Interface Builder. The build error shows in the output detail (Figure 1), and shows "Failed" in the main status pane - with a warning icon (Figure 2).
Figure 1
Figure 2
The failure trace leads to the bridging header import line in my *.m Objective-C files :
#import "TestApp-Swift.h"
So.. I have an objective-c view controller (*.m) that creates the SettingsViewController.swift view, but it throws this error. I am not subclassing from swift, just using the bridging header in a view.m and a project that has a swift view that sub-classes a swift library class.
Here is how I create SettingsViewController for navigation in my .m file:
UIViewController *settingsVC = [self.storyboard instantiateViewControllerWithIdentifier:#"SettingsTableViewController"];
if (settingsVC) {
[self.navigationController pushViewController:(UIViewController*)settingsVC animated:true];
}
else {
NSLog(#"ERROR, Could not segue to Settings Table View.");
}
Any help will make me happy. The Interface Builder needs to happily show my IBDesignables and keep working if I use Swift libraries for views in this mixed project.
Related
I am creating a swift framework which has some reusable UI components.
When I am importing this framework in another application, I am able to add custom component programmatically.
But, if I add UIView on storyboard and change its class to customComponent, I am not able to see its preview on storyboard. Due to this i cannot distribute this framework to other developers as they can't visualize the component in InterfaceBuilder.
Though, I can see the component at run-time, it reduces the effectiveness of using framework in storyboard.
I have followed a link to develop swift framework.
Thre are two projects Library and SampleApp.
Libray : This is a swift framework which as one custom ui component as MyButton. its very basic ui just to avoid any confusion.
SampleApp : This application uses Library to show MyButton on sample screen
Please let me know the way i can see the preview of custom UI component from framework in any other application.
Edit1:
I have uploaded my sample code where I have applied the suggestions, but not able to resolve this.
Code
Edit 2:
Rectified the broken link of tutorial. I have not used outlets just to make it simpler.
Edit 3:
There are two projects: Library and SampleApp
I have MyButton.swift as a custom widget in Library project.
I have added UIView in StoryBoard and changed its class to MyButton(from library Framework)
Certainly there is!
After you import your framework:
import MyFramework
In IB, select the framework module:
EDIT:
Of course, I'm assuming you've made the custom components IBDesignable.
EDIT #2:
There should be no need to "import" into your storyboard. All you want to do is make sure that your view controller code has the import in it and that your storyboard's view controller is that subclass. For instance, here's a view controller named MainViewController:
And to set your view to be controlled by it:
I may be in compiler hell right here.
I'm implementing a Snapshot test in Swift, calling a property on an Objective-C VC, but that property is a class, written in Swift, bridged in.
In MyViewController.h:
#class TextEntryView;
#interface MyViewController: AbstractTextEntryViewController
#property (nonatomic, strong) TextEntryView *textEntryView;
#end
In TextEntryView.swift:
#objc(TextEntryView) class TextEntryView: UIView
And in my test, I'm trying to call
vc.textEntryView where vc is of type MyViewController and I'm getting the error:
value of type MyViewController has no member textEntryView
My bridging headers look good. If I add an NSString property to the .h file above, I'm able to reference it in the test. Also, when I command-click on MyViewController in my test, it takes me to the .h file rather than the .swift generated version of that file (which seems like a symptom of this problem).
I may be pushing Xcode 8 beyond its limits.
You need to make sure you import your app at the top of the source file for your test. For example, if your app is called MyApp, insert at the top of the test file:
import MyApp
If I leave out the import, I get the same behavior you are seeing. Additionally, as long as the import is there, you shouldn't have to bother with bridging headers for the unit test.
Have you tried to import to Test Target ?
Since you already imported the Xcode-generated header file for your Swift code into Objective-C .m file.
Please also remove #objc annotation from TextEntryView class since it's a subclass of UIView thus accessible and usable in Objective-C. keeping the annotation #objc may cause a side effect.
To be accessible and usable in Objective-C, a Swift class must be a
descendant of an Objective-C class or it must be marked #objc.
a simple case of "side-effect" is when a (swift) UIViewController subclass is marked #objc and used as custom subclass in storyBoard:
instantiateViewControllerWithIdentifier will instantiate a UViewController instead of the subclass we set in the storyBoard.
with error Unknown class _TtC10AbcdViewController in Interface Builder file
I am working on a project which somewhere needs to send the edited image to another ViewControler using segue or storyboard.
Some points to understand first.
The ViewController i am sending image which is configured using Objective C.
And the image is to be pass that ViewController which is configured using Swift Lang.
Problem:
The Swift Class which is imported in Objective .m file is not visible so it lets me to create its object to make reference of its members.
I tried:
// here i am not able to create SwiftVC class object so i can pass image further
SwfitVC *object = [self.storyboard instantiateViewControllerWithIdentifier:#"VC_Identifire"];
object.image = image;
[self.navigationController pushViewController:object animated:YES];
SwftVC Class is not visible after importing to .m file.
Please have look. Thanks.
In order to make your Swift file visible; in your .m file you'll have to write this import statement.
#import "YourProjectName-Swift.h"
Clean and build then you'll be able to use your Swift class.
Alternate way:
You can save the image to Document Directory in Objective-c class and fetch it into Swift Class.
Might be a help this logic.
I had two separate Xcode projects that I have fused into a single one: a speech to text recognizer that is implemented with a XIB file, written in Objective-C, and another project that is just a conventional UI written in Swift with some more stuff. Both projects work flawlessly by themselves.
I have cleaned out all the errors, and created a Bridging header file. So far, both Swift and Objective-C modules coexist, but obviously only the Swift part runs.
I want to open the Objective-C XIB and display it in my swift-coded UI.
According to your screenshot, I assume you are using storyboard for your UI in your Swift application.
As your legacy UI is on XIB files, you need to load it programatically. To do that, you'll have to use loadNibNamed method like in the following example :
var nibs = NSBundle.mainBundle().loadNibNamed("Counter", owner: self, options: nil)
for v in nibs {
if (v is Counter) {
someViewInStoryboard.addSubview(v)
}
}
Here I have a Counter.xib file which contains an custom UIView. Class for this view is Counter, which extends UIView.
So when your XIB is loaded, browse it to find your custom view, then add it as a subview of an existing UIView in your storyboard. Variable someViewInStoryboard in my example is an IBOutlet of this UIView.
I'm attempting to add an external library written in Swift to my Objective-C project. The library is here:
https://github.com/Ramotion/animated-tab-bar
I followed their instructions by adding the RAMAnimatedTabBarController to my project, then modifying my `Tab Bar controller , Tab Bar items to utilize the custom class in the storyboard.
It keeps crashing with unknown class messages in the logs, so even though autocomplete on the custom class worked, it clearly can't see/compile the project files:
2015-05-01 14:59:26.309 <project>[xxxx:xxxxx] Unknown class RAMAnimatedTabBarItem in Interface Builder file.
2015-05-01 14:59:26.350 <project>[xxxx:xxxxx] Unknown class RAMAnimatedTabBarController in Interface Builder file.
2015-05-01 14:59:26.353 <project>[xxxx:xxxxx] Unknown class RAMBounceAnimation in Interface Builder file.
I've read a bunch of stuff about including swift header files in order to interchange using objc and swift in your projects, but they mention importing into your ViewController classes (of which I don't have since TabBar and NavController are only in the storyboard).
How to access both Objective-C and Swift classes from same storyboard?
Still pretty new with storyboards and I feel like I'm missing a critical piece here. Help!
I managed to get it working...
Set Tab Bar controller to RAMAnimatedTabBarController
Select tab bar item > Identity Inspector and set class to RAMAnimatedTabBarItem and module to RAMAnimatedTabBarController
Drag in your object and hook it up as per the video tutorial here: http://vimeo.com/112390386
Click the object and set class to (anything you want, e.g. RAMBounceAnimation) and ensure the module is RAMAnimatedTabBarController
Also make sure :
setting the module in the identity inspector on the animation object
you set a duration on the object attribute inspector and press enter
Setting module to RAMAnimatedTabBarController