Create ToDo using Realm—Expected member name or constructor call after type name

Asked 2 years ago, Updated 2 years ago, 46 views

[For beginners] Completely detailed!Tutorial to create a ToDo app with cocoapod+Realm (4 times in total) - Qiita

I made ToDo according to the tutorial on the page above, but in the code below, return realm.objects(ToDo),

Expected member name or constructor call after type name

You will see the error

I was able to resolve the other error, but I couldn't erase the error in this part.
Could you tell me how to solve this problem?

source code

import UIKit
import RealmSwift

classViewController:UIViewController {

  @IBOutlet var todoNameText:UITextField!

  @IBOutlet variableView:UITableView!

  var toDoItems:Results<ToDo>?{
    do{
      let realm = try Realm()
      return realm.objects (ToDo)
    }catch {
      print("Error")
    }
    return nil
  }

swift realm

2022-09-30 11:38

1 Answers

Pass the class object (meta type) to the Realm.objects(_:) parameter.
Swift grammar requires .self after ToDo.self and ToDo.self to obtain the meta-type.


2022-09-30 11:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.