CountDownTimer android abstract in Swift

Hi,

I am trying to use the CountDownTimer in a Cooper app using Fire for Swift. (Compiling with EBuild) and I can’t seem to figure it out.

https://developer.android.com/reference/android/os/CountDownTimer.html

Here is my code. Any ideas would be awesome. thanks! Funny thing is I was pretty sure this code compiled a couple months ago.

import java.util
import android.app
import android.content
import android.os
import android.util
import android.view
import android.widget

public class MainActivity: Activity {

public override func onCreate(_ savedInstanceState: Bundle!) {
	super.onCreate(savedInstanceState)
	ContentView = R.layout.main

	let imgone = self.findViewById(R.id.ivDiceOne) as! ImageView
	let imgtwo = self.findViewById(R.id.ivDiceTwo) as! ImageView
	let imgthree = self.findViewById(R.id.ivDiceThree) as! ImageView
	let imgfour = self.findViewById(R.id.ivDiceFour) as! ImageView
	let imgfive = self.findViewById(R.id.ivDiceFive) as! ImageView

	class MyCount : CountDownTimer {
		//  public init(_ millisInFuture: Int64, _ countDownInterval: Int64) {
		// super.init(millisInFuture, countDownInterval)
		//  }

		// @Override
		override public func onFinish() {

		}

		// @Override
		override public func onTick(_ millisUntilFinished: Int64) {


			let rand1 = Random()
			var r1 = rand1.nextInt(6) + 1;

			if r1 == 1 {imgone.setImageResource(R.drawable.dice1)}
			if r1 == 2 {imgone.setImageResource(R.drawable.dice2)}
			if r1 == 3 {imgone.setImageResource(R.drawable.dice3)}
			if r1 == 4 {imgone.setImageResource(R.drawable.dice4)}
			if r1 == 5 {imgone.setImageResource(R.drawable.dice5)}
			if r1 == 6 {imgone.setImageResource(R.drawable.dice6)}

			let rand2 = Random()
			let r2 = rand2.nextInt(6) + 1

			if r2 == 1 {imgtwo.setImageResource(R.drawable.dice1)}
			if r2 == 2 {imgtwo.setImageResource(R.drawable.dice2)}
			if r2 == 3 {imgtwo.setImageResource(R.drawable.dice3)}
			if r2 == 4 {imgtwo.setImageResource(R.drawable.dice4)}
			if r2 == 5 {imgtwo.setImageResource(R.drawable.dice5)}
			if r2 == 6 {imgtwo.setImageResource(R.drawable.dice6)}

			let rand3 = Random()
			let r3 = rand3.nextInt(6) + 1

			if r3 == 1 {imgthree.setImageResource(R.drawable.dice1)}
			if r3 == 2 {imgthree.setImageResource(R.drawable.dice2)}
			if r3 == 3 {imgthree.setImageResource(R.drawable.dice3)}
			if r3 == 4 {imgthree.setImageResource(R.drawable.dice4)}
			if r3 == 5 {imgthree.setImageResource(R.drawable.dice5)}
			if r3 == 6 {imgthree.setImageResource(R.drawable.dice6)}

			let rand4 = Random()

Ok so maybe just ignore all the code above and answer one question for me. If you want to inherit from a class in Android like CountDownTimer(which is an abstract class in Android) how do you do that using the Swift language since something like this does NOT work.

class myCountDownTimer: CountDownTimer {
// some code…
}

It always returns “Cannot instanciate abstract class”

Do you have any suggestions? I am sure I am missing something.

Thanks!!!

That doesn’t mean you can’t inherit from it. it just means that you haven’t implemented all the abstract (i.e. missing) methods from the base class, and thus your descendant its till abstract as well. You should see individual error messages on the class declaration for each method you are missing.

ok thanks, I will double check that.

1 Like