Westopher
Westopher

Reputation: 35

Why do I keep getting the error "no such module 'realmswift'"?

The previous answers to this question are over a year old. I've tried them. They don't really work. I have installed the pod for using Realm successfully. I wrote a couple of users with a name and role onto the Realm database that I could see with Realm Studio. I then walked away from my computer for an hour (no one else touched it during this time). When I got back I got the no such module error.

I have tried to update the pod file several times through the terminal. I also quit Xcode and restarted it. I also Google-ed around looking for a solution and tried adding a new scheme via the Product drop down. Although that will get my project to successfully compile, the new scheme won't launch on the simulator.

This is my podfile:

# Uncomment the next line to define a global platform for your project
# platform :ios, '12.2'

target 'realmProject' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!

# Pods for realmProject
pod 'RealmSwift'

end

This is the ViewController that is giving me the error:

import UIKit
import RealmSwift

class SecondViewController: UIViewController {
    @IBOutlet weak var nameTextField: UITextField!

    @IBOutlet weak var rolePickerView: UIPickerView!

    let roles = ["Designer", "Developer"]

    override func viewDidLoad() {
        super.viewDidLoad()
        rolePickerView.dataSource = self
        rolePickerView.delegate = self
    }

    var employees = Employee()

    @IBAction func addButtonPressed(_ sender: Any) {


        employees.name = nameTextField.text ?? "no name"

        employees.role = roles[rolePickerView.selectedRow(inComponent:     0)]

        let realm = try! Realm()

        try! realm.write {
            realm.add(employees)
        }

        let results = realm.objects(Employee.self)

        for r in results {
            employees.append(r)
        }

        print("button pressed")

    }
}

extension SecondViewController: UIPickerViewDelegate, UIPickerViewDataSource {

    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }

    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return roles[row]
    }

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return roles.count
    }
}

I am simply trying to use Realm to save data and use that to populate a tableview. Right now I get the above error saying I can't use Realm.

Upvotes: 1

Views: 4833

Answers (2)

Ali Xhah
Ali Xhah

Reputation: 118

Best way to resolve this issue is follow these steps

1) click on project or in product in xcode then click on manage scheme

2) after uncheck your project and check your pod u have installed

3) Build your application with your pod

4) After again change your scheme and uncheck pod and check your app this will works , i added images to explain this :)

First Image

Build like this Build like this

Upvotes: 5

Victor Sanchez
Victor Sanchez

Reputation: 983

Had the same problem with other pods, such as Firebase.

Quickfix: to go to editor, clean Build Folder, then select the Pods Project and build it for a Generic iOS device. After that, build your project again for your desired target. This sometimes solves the error of "no such module".

If this doesn't work, close Xcode, run rm -rf ~/Library/Developer/Xcode/DerivedData/ on terminal, open Xcode again and build again.

Upvotes: 3

Related Questions