Overriding Method With Selector 'Touchesbegan:Withevent:' Has Incompatible Type '(Nsset, Uievent) -≫ ()'

Overriding method with selector 'touchesBegan:withEvent:' has incompatible type '(NSSet, UIEvent) - ()'

Swift 1.2 (Xcode 6.3) introduced a native Set type that bridges
with NSSet. This is mentioned in the Swift blog and in the
Xcode 6.3 release notes, but apparently not yet added to the official documentation (update: As Ahmad Ghadiri noted, it is documented now).

The UIResponder method is now declared as

func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent)

and you can override it like this:

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
if let touch = touches.first as? UITouch {
// ...
}
super.touchesBegan(touches , withEvent:event)
}

Update for Swift 2 (Xcode 7): (Compare Override func error in Swift 2)

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
if let touch = touches.first {
// ...
}
super.touchesBegan(touches, withEvent:event)
}

Update for Swift 3:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
// ...
}
super.touchesBegan(touches, with: event)
}

Overriding touchesBegan in Swift

As of iOS 8.3, touchesBegan takes a touches parameter which is a Set<NSObject>. It's now Set<UITouch>. So, you would:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let point = touches.first?.location(in: view) else { return }

// use `point` here
}

In previous iOS versions, touchesBegan was defined as a NSSet parameter, as outlined in the question, so you would:

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
if let touch = touches.anyObject() as? UITouch {
let touchPoint = touch.locationInView(view)
...
}
}

Swift: overriding method with selector has incompatible type

When I try to autocomplete that class function from somewhere else in Swift, Xcode tells me that param is an [NSObject: AnyObject]!, which makes the method declaration work:

override class func someFunction(param: [NSObject: AnyObject]!) -> AnyObject? {
return "Foo"
}

This might be a compiler bug, since I'm pretty sure that's supposed to bridge properly to NSDictionary! (it seems to be bridging one way, but not the other, or something).

Overriding method with selector has incompatible type - Swift

Remove implicit optional type.Check in UITableViewDataSource there is no optional for tableView,indexPath.Also remove override as you implementing the protocol methods you do not need to write override

Replace with below method

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
//the error is on the line oboe... Overriding method with selector 'tableView:cellforRowAtIndexPath:'has incompatible type '(TableView, NSIndexpath) -. UITableViewCell!'
{
let cell = tableView.dequeueReusableCellWithIdentifier("cellIdent", forIndexPath: indexPath) as UITableViewCell

// Configure the cell...

return cell
}

Override func error in Swift 2

You're getting your first error because much of Cocoa Touch has been audited to support Objective-C generics, meaning elements of things like arrays and sets can now be typed. As a result of this, the signature of this method has changed and since what you've written no longer matches this, you're given an error explaining that you've marked a method as override but it doesn't actually match any methods from the super class.

Then when you remove the override keyword, the error you're getting is letting you know that you've made a method that has a conflicting Objective-C selector with the real touches began method (unlike Swift, Objective-C doesn't support method overloading).

The bottom line is, in Swift 2, your touches began override should look like this.

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
// stuff
}

For more information on what Objective-C generics mean for your Swift code, I suggest you take a look at the Lightweight Generics section in the prerelease version of Using Swift with Cocoa and Objective-C. As of now on pages 33 & 34.

Compiler error: Method with Objective-C selector conflicts with previous declaration with the same Objective-C selector

Objective-C does not support method overloading, you have to use a different method name. When you inherited UIViewController you inherited NSObject and made the class interopable to Obj-C. Swift on the other hand does support overloading, that's why it works when you remove the inheritance.

Method conflicts with Method from Superclass - Override gives error

The signature (from the docs) for this method is...

func touchesBegan(_ touches: Set<UITouch>, withEvent event: UIEvent?)

touches is a Set (not NSSet) of UITouch objects and event is an optional UIEvent.

You also need to override it...

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.menuHelper(touches)
}

Storing a file in a database as opposed to the file system?

Have a look at this answer:

Storing Images in DB - Yea or Nay?

Essentially, the space and performance hit can be quite big, depending on the number of users. Also, keep in mind that Web servers are cheap and you can easily add more to balance the load, whereas the database is the most expensive and hardest to scale part of a web architecture usually.

There are some opposite examples (e.g., Microsoft Sharepoint), but usually, storing files in the database is not a good idea.

Unless possibly you write desktop apps and/or know roughly how many users you will ever have, but on something as random and unexpectable like a public web site, you may pay a high price for storing files in the database.

Overriding method with selector init has incompatible type in Swift

Simply change some variable names, conflicting and remove that override keyword with init;

public class CombinedChartRenderer: ChartDataRendererBase {

private weak var _chart: CombinedChartView!

public init(chart: CombinedChartView, animator: ChartAnimator, viewPortHandler: ChartViewPortHandler)
{
super.init(animator: animator, viewPortHandler: viewPortHandler)

_chart = chart

createRenderers()
}
}

public class MyCombinedChartRenderer: CombinedChartRenderer {
private weak var _myChart: MyCombinedChartView!
public init(myChart: MyCombinedChartView, animator: ChartAnimator, viewPortHandler: ChartViewPortHandler)
{
super.init(chart: myChart, animator: animator, viewPortHandler: viewPortHandler)

_myChart = myChart // This can be removed by marking baseclass instance '_chart' as public;
}
}


Related Topics



Leave a reply



Submit