I'm using the WKScriptMessageHandler in my iOS App to receive messages from the Webkit. I'm using the WKScriptMessageHandler protocol, but apparently after upgrading Xcode to the most recent 6.1 upgrade, I am now getting this error message:
Type 'ViewController' does not conform to protocol 'WKScriptMessageHandler'
Any ideas on how this should be done now? Why did Apple change this
Here is my code below:
import UIKit
import WebKit
class ViewController: UIViewController, WKScriptMessageHandler {
#IBAction func fourButton(sender: UIButton){
performSegueWithIdentifier("login", sender: self)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func userContentController(userContentController: WKUserContentController!, didReceiveScriptMessage message: WKScriptMessage!){
println("got message: \(message.body)")
}
}
The function definition has changed, remove the exclamation marks:
func userContentController(userContentController: WKUserContentController, didReceiveScriptMessage message: WKScriptMessage)
Related
I am building an app that should connect to my raspberry pi but after installing MQTT via cocoaPods the import CocoaMQTT gives me this error
"Could not build Objective-C module 'CocoaMQTT'"
I've already deleted my derivedData but thats not working either.
how can I fix this?
import UIKit
import CocoaMQTT -> Could not build Objective-C module 'CocoaMQTT'
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
#IBAction func test(_ sender: UISwitch) {
}
}
Ok i've fixed it by compiling for a lower iOS deployment.
I created a pod library in here
Library contains a protocol. When I install library from cocoapods and try to conform the protocol I got delegate is inaccessible due to 'internal' protection level error.
The protocol:
#objc public protocol TDDropdownListDelegate {
func listTapped(sender: UIButton)
}
The protocol function:
open func listTapped(sender: UIButton) {
activate(sender: sender)
delegate?.listTapped(sender: sender)
}
The code I got the error
import UIKit
import TDDropdownList
class ViewController: UIViewController,TDDropdownListDelegate {
let a = TDDropdownList(frame: CGRect(x: 100 , y: 100 , width: 200 , height: 75))
override func viewDidLoad() {
a.initialize(data: ["Emre","Duman"])
a.delegate = self // LINE I GOT THE ERROR
self.view.addSubview(a)
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
func listTapped(sender: UIButton) {
print(sender.currentTitle!)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
I've been trying to set up the CocoaPods CVCalendar for my app, but after integrating it into my Xcode project, the content fails to show through the UIViews. Essentially, whenever I connect the views to the CVCalendarView and CVCalendarMenuView variables, the views simply do not show. Here's the ViewController code I have so far, and help would be greatly appreciated!
import UIKit
import CVCalendar
class ViewController: UIViewController, CVCalendarViewDelegate, CVCalendarMenuViewDelegate {
#IBOutlet weak var menuView: CVCalendarMenuView!
#IBOutlet weak var calendarView: CVCalendarView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
calendarView.commitCalendarViewUpdate()
menuView.commitMenuViewUpdate()
}
func presentationMode() -> CalendarMode {
return .MonthView
}
func firstWeekday() -> Weekday {
return .Sunday
}
}
Your ViewController class is the class in the storyboard?
Did you hook up the delegates? Delegate setup
You're delegating the rendering to your ViewController/
You need to drag to the yellow view controller nub.
If for some reason you'd like to setup CVCalendar manually you have to do the following steps.
Refer here
I'm new in swift and I'm studying the delegate and protocols. In my test application I'm using this protocol declaration (in ViewController1) and I have this code:
import UIKit
//Protocol declaration
protocol viewController1Delegate
{
func didFinish(controller:ViewController1,text:String)
}
//ViewController1 class
class ViewController1: UIViewController {
//delegate declaration for viewController1
var delegate:ViewController1? = nil
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
valore.text=valoreInput
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func doneWithOK(sender: AnyObject) {
delegate?.didFinish(self,"done")
}
}
My problem is XCode show me an error: ViewController1 does not have a member named didFinisch. What is wrong in my code? Someone can help me to understand the problem?
delegate should be viewController1Delegate? and not ViewController1?.
I just started coding with Swift and I try to build a calculator. When I launch the simulator and I click the button '1' of the calculator it calls Tap0 function. I encountered the following issue: Can't unwrap Optional.None.
import UIKit
class ViewController: UIViewController {
#IBOutlet var display:UITextField
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
#IBAction func Tap0(sender:AnyObject){AddNumber("0")}
func AddNumber(x:String){
self.display.text="" //ERROR (Can't unwrap Optional.None)
println(self.display.text)
}
}
How I can solve it?
As what rdelmar suggested, to solve the error, connect display to the UITextField in StoryBoard: