I have an existing Sample Objective-C app that uses Salesforce's SDK. I am trying to convert it to use Swift one-class at a time. Salesforce SDK has a class called 'SFRestRequest.h' that has 'SFRestDelegate' delegate.
In Objective C, I have a class called 'RootViewController.h' that is a subclass of UITableViewController. It implements SFRestDelegate. It works fine.
//RootViewController.h
#import <UIKit/UIKit.h>
#import "SFRestAPI.h"
@interface RootViewController : UITableViewController <SFRestDelegate> {
NSMutableArray *dataRows;
IBOutlet UITableView *tableView;
}
I am trying to create a RootVC.swift file to replace RootViewController Objective-c class.
I have a bridging header file that imports all those headers that are imported in objective-c
//SwiftForce-Bridging-Header.h
#import "SFRestAPI.h"
#import "SFRestRequest.h"
My RooVC.Swift file looks like:
import UIKit
class RootVC: UITableViewController,SFRestDelegate {
..
..
}
Now, if I command+click on the SFRestDelegate, it correctly goes to protocol implementation. However, if I try to build, I get.. "Cannot find Protocol declaration SFRestDelegate Error!
SWIFT_CLASS("_TtC10SwiftForce6RootVC")
@interface RootVC : UITableViewController <SFRestDelegate>
@property (nonatomic) NSArray * dataRows;
- (instancetype)initWithStyle:(UITableViewStyle)style OBJC_DESIGNATED_INITIALIZER;
- (void)viewDidLoad;
- (void)didReceiveMemoryWarning;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
@end
Appreciate any help. You can test it by downloading the app from: https://github.com/rajaraodv/SwiftForce
I just sent you a pull request to the repo you linked which solves the problem.
Your problem appears to be an issue with the load order of the Swift and Objective-C classes and headers. You have to make sure that any headers required by your Swift classes are compiled before the Swift code is compiled. This is handled fairly seamlessly with simple .h and .m Objective-C files, but when using static libraries (as in your project) the .pch file seems to be the most appropriate place to import any headers that your Swift code needs at compile time.
Adding this line to your SwiftForce-Prefix.pch file seems to work:
#import <SalesforceNativeSDK/SFRestRequest.h>
This doesn't seem very elegant (just like the Bridging-Header solution) however only time will tell if this is a bug or a best practice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With