Here is my custom class that I have created:
import UIKit
import CoreBluetooth
protocol vaBeanDelegate
{
}
class vaBean: CBCentralManager, CBCentralManagerDelegate {
override init!(delegate: CBCentralManagerDelegate!, queue: dispatch_queue_t!) {
println("bean initialised")
super.init()
self.delegate = delegate
}
func centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData: [NSObject : AnyObject]!, RSSI: NSNumber!) {
println("discovered peripheral(s)")
}
func centralManagerDidUpdateState(central: CBCentralManager!) {
switch (central.state) {
case .PoweredOff:
println("hardware is powered off")
case .PoweredOn:
println("hardware is powered on and ready")
//centralManager.scanForPeripheralsWithServices(nil, options: nil)
case .Resetting:
println("hardware is resetting")
case .Unauthorized:
println("state is unauthorized")
case .Unknown:
println("state is unknown");
case .Unsupported:
println("hardware is unsupported on this platform");
}
}
func centralManager(central: CBCentralManager!, didConnectPeripheral peripheral: CBPeripheral!) {
println("didConnectPeripheral")
}
}
I just don't know how to initialize it from my main ViewController. When I try the following it complains that ViewController does not conform to the CBCentralManagerDelegate:
import UIKit
class ViewController: UIViewController {
var myBean: vaBean!
override func viewDidLoad() {
super.viewDidLoad()
println("blueToothTest v1.00")
println("opening bluetooth connection ...")
myBean = vaBean(delegate: self, queue: nil)
}
override func didReceiveMemoryWarning() {super.didReceiveMemoryWarning()}
}
Multiple Inheritance is a feature of C++ where a class can inherit from more than one classes. The constructors of inherited classes are called in the same order in which they are inherited. For example, in the following program, B's constructor is called before A's constructor.
Yes in Swift and Objective-c Single and Multilevel inheritance is supported. In swift and many other languages Multiple Inheritance is restricted by use of classes because of historical problems like deadly diamond and others ambiguities.In swift you can achieve the Multiple inheritance at some level by Protocols .
Like other OOP languages, Swift also supports the concept of class inheritance. Inheritance allows us to create a new class from an existing class.
Swift and Objective-C are single inheritance only, you can't have more than one superclass for a class.
When you see Swift code with what looks like multiple superclasses in their declaration, you'll see that at most, one of the names in the declaration is a superclass, the others are names of protocols.
In Objective-C the these would have been written with <angled brackets>
but this is not the case for Swift.
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