Unable to configure dataSource and delegate

So, I updated the Xcode and GitHub project code to swift 3.0 (my project is in Obj C, and some of the modules I use from GitHub are in Swift). I got a bunch of bugs and now I'm stuck on these. For some reason, my dataSource and delegate for floatActionButton ( git here ) no longer work. I tried setting the dataSource and delegate programmatically and on the storyboard, but that didn't work.

Errors:

Property 'dataSource' not found on object of type 'LiquidFloatingActionButton *'

Property 'delegate' not found on object of type 'LiquidFloatingActionButton *'

I believe that if I find out the problem of dataSource and delegate , then it will fix the color error below.

Screenshot: enter image description here

.h:

 #import <UIKit/UIKit.h> #import "ProductContentViewController.h" #import "LiquidFloatingActionButton-swift.h" @interface SetScreenViewController : UIViewController <UIPageViewControllerDataSource, LiquidFloatingActionButtonDelegate, LiquidFloatingActionButtonDataSource> ... @end 

.m:

  #import "LiquidFloatingActionButton-Swift.h" LiquidFloatingActionButton *floatingActionButton; NSMutableArray *liquidCells; bool *closeFloatingButtons; NSString *videoToWatchURL; - (void)addLiquidButton{ //Grabs the coordinates bottom right of the screen float X_Co = self.view.frame.size.width - 50; float Y_Co = self.view.frame.size.height - 50; //i subtract 10 so the button will be placed a little bit out X_Co = X_Co - 10; Y_Co = Y_Co - 10; //I create each cell and set the image for each button liquidCells = [[NSMutableArray alloc] init]; [liquidCells addObject:[[LiquidFloatingCell alloc]initWithIcon:[UIImage imageNamed:@".png"]]]; [liquidCells addObject:[[LiquidFloatingCell alloc]initWithIcon:[UIImage imageNamed:@".png"]]]; [liquidCells addObject:[[LiquidFloatingCell alloc]initWithIcon:[UIImage imageNamed:@".png"]]]; [liquidCells addObject:[[LiquidFloatingCell alloc]initWithIcon:[UIImage imageNamed:@".png"]]]; [liquidCells addObject:[[LiquidFloatingCell alloc]initWithIcon:[UIImage imageNamed:@".png"]]]; [liquidCells addObject:[[LiquidFloatingCell alloc]initWithIcon:[UIImage imageNamed:@".png"]]]; //Sets the floating button at the loaction provided floatingActionButton = [[LiquidFloatingActionButton alloc] initWithFrame:CGRectMake(X_Co, Y_Co, 50, 50)]; floatingActionButton.dataSource = self;//Error here floatingActionButton.delegate = self;//and here. //I set the color of the floating button floatingActionButton.color = [self colorWithHexString:@"01b8eb"]; //Enables the user interaction fuction to true so itll open or close floatingActionButton.userInteractionEnabled = YES; //Adds the flaoting button to the view [self.view addSubview:floatingActionButton]; } -(NSInteger)numberOfCells:(LiquidFloatingActionButton *)liquidFloatingActionButton{ return liquidCells.count; } -(LiquidFloatingCell *)cellForIndex:(NSInteger)index{ return [liquidCells objectAtIndex:index]; } 

PodFile:

 # Uncomment this line to define a global platform for your project # platform :ios, '9.0' target 'Whats New' do # Uncomment this line if you're using Swift or would like to use dynamic frameworks # use_frameworks! # Pods for Whats New target 'Whats NewTests' do inherit! :search_paths # Pods for testing end target 'Whats NewUITests' do inherit! :search_paths # Pods for testing end pod 'CRToast', '~> 0.0.7' pod "LiquidFloatingActionButton" pod 'DGActivityIndicatorView' pod 'M13ProgressSuite' pod 'SDWebImage', '~>3.8' pod 'FSCalendar' use_frameworks! post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['SWIFT_VERSION'] = '3.0' end end end end 

UPDATE BELOW

I ended up using this project because the original GitHub was not fixed, thanks for all the help, and if anyone finds out please, let everyone know here!

+7
git ios objective-c delegates datasource
source share
4 answers

If swift @protocols not detected using @objc , you cannot access them in objective-c,

eg

 @objc public protocol xxxxxxxxxxxDelegate { func functionOne() func functionSecond() } 
+3
source share

I think the problem is that your Objective-C code does not know the " open var " s dataSource and delegate code of LiquidFloatingButton Swift.
Making them known requires the Obj-c header file, which provides this Swift data for your Obj-C code. This is described in detail in the Apple documents “ Swift and Objective-C in the same project ”, in your case, in particular, in the section “Importing external wireframes”. It says:
You can import the framework into any Objective-Cm file in another target environment using the following syntax:

 @import FrameworkName; 
+1
source share

Have you added a bridge title to your project? To use Swift code in an Objective-C project, you need a bridge header. Here what to do

1.Create a new .swift file

2. A popup will appear and ask, "Do you want to customize the Objective-C header . " Select Yes .

3.Click on the Xcode project file, click Build Settings

4. Find the search bar and find the Define module .

5. Change the value to Yes .

6. In application build, add the following: #import "YourProjectName-swift.h"

Whenever you want to use your Swift file, you should add the following line:

 #Import "YourProjectName-swift.h" 
+1
source share

I also use LiquidFloatingActionButton in a Swift 3 project. Note that the git project uses SnapKit for Swift 2.3 , which I also had to deal with, but it is not available here. The solution for me was not to use @objc public protocol , but to change the protocol declaration as follows:

 public protocol LiquidFloatingActionButtonDataSource { func numberOfCells(_ liquidFloatingActionButton: LiquidFloatingActionButton) -> Int func cellForIndex(_ index: Int) -> LiquidFloatingCell } 

And:

 public protocol LiquidFloatingActionButtonDelegate { // selected method func liquidFloatingActionButton(_ liquidFloatingActionButton: LiquidFloatingActionButton, didSelectItemAtIndex index: Int) } 

Only I could successfully use delegation in my Swift 3 project.

0
source share

All Articles