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.
Related
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.
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 wanted to use a library however it required me to change MyTabBarViewController class to its own class (its own TabBarController - 138) installed using cocoapod. I couldn't figure out how to do it (or if it's possible) but that would be nice for me to be able to use MyTabBarViewController as well so I can have my stuff separated, such as viewDidLoad and my functions.
I was using MyTabBarViewController instead of this but the library requires me to change it to this.
Is there a way to make my TabBarVC getting called with a line inside the library's TabBarVC? Or should I write inside the library's TabViewController?
I have to use a library for my iOS project.
the library offers the class ICDevice (abstract) with a delegate ICDeviceDelegate.
the ICDeviceDelegate offers the following funtion
-(void)accessoryDidConnect:(ICISMPDevice *)sender;
I want to integrate this function in my ViewController to detect when the device is connected. How to do that?
Go to your .h and set your controller as delegate of the library #interface YourViewController : UIViewController <LibraryDelegate> so then you will be able to set your view controller as delegate when creating the library object
YourLibrary *library = [YourLibrary new];
library.delegate = self;
Delegates are a very important pattern in Cocoa/CocoaTouch, I suggest you read Apple's documentation to get a good grasp on it.
Once you understand them properly, it should be trivial to figure out the answer to your question.
Documentation
I am trying to add pull to refresh to my app and am using the Pull to Refresh files here: https://github.com/leah/PullToRefresh However I am confused on how to make a subclass of my table view. How does one do that?
You mean something like this?
#interface MyTableViewController : PullRefreshTableViewController
{
//Member variables here.
}
// Methods and protocols here.
#end