swift - 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.
解决方案
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 :)
推荐阅读
- r - R:将向量放入箱中,然后找到这些箱的平均值
- python - 如何在熊猫数据框中获取特定日期/时间的所有历史值?
- sql - JSON_EXTRACT 不适用于 BigQuery 中的布尔值
- javascript - 无法将来自 Joke API 服务器的响应呈现到视图 ASP.NET Core 5.0 MVC
- reactjs - 如何使 VSCode 和 Prettier 扩展忽略 React JSX 元素的空格?
- javascript - 使用 acuityscheduling API 表达
- c - 用空格替换hypen(指针错误)语言c
- c# - 为什么工作服务模板没有像 systemd 一样正常关闭?
- swift - Unable to run WatchKit app when support running without iOS app installation is unchecked
- aws-amplify - Amplify React Federated 登录要求每次登录时验证电子邮件