So i upgraded Xcode and the GitHub project code to swift 3.0 (my project is in Obj C and some of the pods i use from GitHub are in Swift). I got a bunch of errors and now i am stuck on these ones. For some reason my dataSource and delegate for the floatingActionButton (git here) now doesn't work. I tried to set the dataSource
and delegate
programmatically and on storyboard but it didn't work.
Errors:
Property 'dataSource' not found on object of type 'LiquidFloatingActionButton *'
Property 'delegate' not found on object of type 'LiquidFloatingActionButton *'
I believe if i figure out the dataSource
and delegate
issue then it'll fix the colour error below.
Screenshot:
.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 being fixed, thanks for all the help and if someone does figure this out please let everyone here know!
If the swift @protocols
are not define with @objc
then you can't access them in objective-c,
e.g
@objc public protocol xxxxxxxxxxxDelegate {
func functionOne()
func functionSecond()
}
I think the problem is that your Objective-C code does not know the „open var
“s dataSource
and delegate
of the LiquidFloatingButton
Swift code.
To make them known, a Obj-c header file is required that exposes these Swift infos to your Obj-C code. This is described in detail in the Apple docs „Swift and Objective-C in the Same Project“, in your case particularly in the section „Importing External Frameworks“. It says:
You can import a framework into any Objective-C .m file within a different target using the following syntax:
@import FrameworkName;
Did you add a bridging header to your project? To use Swift code in an Objective-C project you need a bridging header. Here's what to do,
1.Create a new .swift file
2.A popup window will appear and ask "Would You like to configure an Objective-C bridging Header". Choose Yes.
3.Click on your Xcode Project file ,Click on Build Settings
4.Find the Search bar and search for Defines Module.
5.Change the value to Yes.
6.In App delegate, add the following : #import "YourProjectName-swift.h"
Whenever you want to use your Swift file you must add the following line :
#Import "YourProjectName-swift.h"
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