Friday July 5th, 2019

Swift App – Fruitrise

By Ebubekir Sezer

Hello, I made a really basic swift application. The name of the application is Fruitrise. When you open the application first, you will see a suprise box and to open this box you can use the button(Open) or you can shake your iPhone and when the box is opened you will see a surprise fruit. This is the idea of the application and i will try to tell how i made this application step by step.

Firstly, I created a Swift project in the Xcode. After the created project i put a UIImageView and i filled this image view entire screen of the iPhone. I made it the background of the application and then in the screen there will be a 3 objects and these are top label, box and button. I am adding these objects to the my application screen.

You can find the images from my github repositories. I added the all necessary images and icons to the project and then i started the make relation between the objects by writing codes. I added the Button, Label and UIImageView to the View Controller side. I created a class that keeping information about the fruits and i initialize the random number that to see different fruits for the every time i opened box or shake the iPhone.

    @IBAction func buttonClicked(_ sender: Any) {
        myButton.setTitle("Roll", for: .normal)
        updateFruit()
    }

    func updateFruit(){
        randomNumber = Int.random(in: 0...9)
        fruit_box_image.image = UIImage(named: AllFruit().fruit_list[randomNumber].fruit_image)
        fruit_title.text = AllFruit().fruit_list[randomNumber].fruit_name  
  }

After these process, I making shaking process which is really simple to apply. We already wrote that updating functions for the Fruits, we just apply that function in the shaking function.

   override func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
        updateFruit()
        myButton.setTitle("Roll", for: .normal)
    }

The application is ready. I made this application using the MCV(Model-View-Controller) structure. Here is the gif from the application;

You can reach the repository from here. You can ask your questions via e-mail or comments to me.