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

删除回忆录丶 提交于 2019-12-13 04:08:17

问题


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.


回答1:


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 :)

Build like this




回答2:


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.



来源:https://stackoverflow.com/questions/55912541/why-do-i-keep-getting-the-error-no-such-module-realmswift

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!