为什么我总是收到错误“没有这样的模块'realmswift'"? [英] Why do I keep getting the error "no such module 'realmswift'"?

查看:239
本文介绍了为什么我总是收到错误“没有这样的模块'realmswift'"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该问题的先前答案已有一年多了.我已经尝试过了.他们真的没有用.我已经安装了Pod,可以成功使用Realm.我在Realm Studio上看到了几个具有名称和角色的用户,他们在Realm数据库中.然后,我离开了计算机一个小时(这段时间内没有人触摸过它).当我回来时,我没有看到这样的模块错误.

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.

我尝试通过终端多次更新pod文件.我还退出了Xcode并重新启动了它.我还用Google编辑寻找解决方案,并尝试通过产品"下拉列表添加新方案.尽管这样可以使我的项目成功编译,但是新方案不会在模拟器上启动.

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.

这是我的podfile:

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

这是给我错误的ViewController:

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
    }
}

我只是试图使用Realm保存数据并使用它来填充表格视图.现在,我收到上述错误消息,说我不能使用Realm.

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.

推荐答案

解决此问题的最佳方法是遵循以下步骤

Best way to resolve this issue is follow these steps

1)单击xcode中的项目或产品,然后单击管理方案

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

2)取消选中您的项目并检查您的Pod是否已安装

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

3)使用广告连播构建您的应用程序

3) Build your application with your pod

4)在再次更改您的方案并取消选中pod并检查您的应用程序是否可以正常运行后,我添加了图片来说明这一点:)

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

像这样构建

这篇关于为什么我总是收到错误“没有这样的模块'realmswift'"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆