Home>

I am creating an ios app.
I wanted to create a screen to evaluate by the number of stars, and decided to use a library called "cosmos".
I am referring to the following site.
Swift-based rating control

You can actually display stars on the screen and increase or decrease the number of stars.
And as the next step, I would like to take the number of stars as a numerical value and print it.
It does n’t work.

According to the site, the following code seems to be able to take the star value
I don't know where to write this.

cosmosView.didTouchCosmos = {rating in
    // Rate value (Double) can be received with rating
}

I've never developed an app or touched swift, and I think it's caused by my lack of knowledge.

Can you tell me what is wrong? . .
Thank you.

↓ view settings screen
] (263de260fb2d1176a365a8db090ae1b0.png)

↓ viewController settings screen

↓ CosmosViewController.swift screen connected to viewController
It will be the file in error

Applicable source code
import UIKit
import Cosmos
class cosmosViewController: UIViewController {
  @IBOutlet weak var cosmosView: CosmosView!
  override func viewDidLoad () {
        super.viewDidLoad ()
    }
  cosmosView.didTouchCosmos = {rating in
         // Rate value (Double) can be received with rating
       print (rate)
     }
}

I researched another site,

import Cosmos
@IBOutlet weak var cosmosView: CosmosView!


I described these two because they seemed necessary.
However, the error did not disappear, so I asked a question.

  • Answer # 1

    Please correct as follows.

    import UIKit
    import Cosmos
    class cosmosViewController: UIViewController {
      @IBOutlet weak var cosmosView: CosmosView!
      override func viewDidLoad () {
            super.viewDidLoad ()
            cosmosView.didTouchCosmos = {rating in
                print (rating)
            }
        }
    }