Swift 2.2,RealmSwift - 无法将'Note'类型的值转换为期望的参数类型Object.Type(Swift 2.2, RealmSwift - Cannot convert value of type 'Note' to expected argument type Object.Type)
我刚开始使用Realm作为记事本应用程序并保存了自定义类的数组(noteTitles)(注意)。 我把它作为一个对象,但是当我使用
realm.objectForPrimaryKey(noteTitles, key: "id")
它给了我一个错误:无法将'Note'类型的值转换为期望的参数类型Object.Type。 在注释的类文件中,我将其作为对象。这是我的ViewController代码:
var note: Note! let realm = try! Realm() @IBOutlet var noteText: UITextView! @IBOutlet var noteTitle: UITextField! func textViewDidEndEditing(textView: UITextView) { try! realm.write{ realm.add(noteTitles) } print("editing ended") } override func viewDidLoad() { super.viewDidLoad() self.noteText.delegate = self realm.objectForPrimaryKey(noteTitles, key: "id")// error here // Do any additional setup after loading the view. }
这是课堂笔记代码:
import Foundation import RealmSwift class Note: Object { var title = "" var content = "" override class func primaryKey() -> String? { return "id" } }
提前感谢您的帮助。
I have just started using Realm for a notepad app and saved the array(noteTitles) of a custom class(Note). I made it as an object, but when I use
realm.objectForPrimaryKey(noteTitles, key: "id")
It gives me an error: Cannot convert value of type 'Note' to expected argument type Object.Type. In the class file for note, I have made it as an object.Here is my ViewController code:
var note: Note! let realm = try! Realm() @IBOutlet var noteText: UITextView! @IBOutlet var noteTitle: UITextField! func textViewDidEndEditing(textView: UITextView) { try! realm.write{ realm.add(noteTitles) } print("editing ended") } override func viewDidLoad() { super.viewDidLoad() self.noteText.delegate = self realm.objectForPrimaryKey(noteTitles, key: "id")// error here // Do any additional setup after loading the view. }
And here is the Class Note Code:
import Foundation import RealmSwift class Note: Object { var title = "" var content = "" override class func primaryKey() -> String? { return "id" } }
Thank You in advance for help.
原文:https://stackoverflow.com/questions/38361196
最满意答案
GitHub在此公共存储库中维护推荐的.gitignore文件的正式列表。
对于Android,你可以在这里找到它
或者只是复制/粘贴:
# Built application files *.apk *.ap_ # Files for the Dalvik VM *.dex # Java class files *.class # Generated files bin/ gen/ out/ # Gradle files .gradle/ build/ # Local configuration file (sdk path, etc) local.properties # Proguard folder generated by Eclipse proguard/ # Log Files *.log # Android Studio Navigation editor temp files .navigation/ # Android Studio captures folder captures/ # Intellij *.iml
GitHub maintains an official list of recommended .gitignore files at this public repository.
For Android you can find it here
Or just copy/paste :
# Built application files *.apk *.ap_ # Files for the Dalvik VM *.dex # Java class files *.class # Generated files bin/ gen/ out/ # Gradle files .gradle/ build/ # Local configuration file (sdk path, etc) local.properties # Proguard folder generated by Eclipse proguard/ # Log Files *.log # Android Studio Navigation editor temp files .navigation/ # Android Studio captures folder captures/ # Intellij *.iml
相关问答
更多-
在Android开发中,哪些文件应该提交到存储库?(In Android development, what files should be committed to a repository?)[2023-10-25]
GitHub在此公共存储库中维护推荐的.gitignore文件的正式列表。 对于Android,你可以在这里找到它 或者只是复制/粘贴: # Built application files *.apk *.ap_ # Files for the Dalvik VM *.dex # Java class files *.class # Generated files bin/ gen/ out/ # Gradle files .gradle/ build/ # Local configuration ... -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
我发现使用更高级别的工具将修订分组在一起并跟踪更改的最佳解决方案。 我们使用redmine来记录所有任务,并且我们的svn修订版会自动加盖。 以这种方式工作,即使修复可能需要7或8次提交,您也可以快速搜索您的日志并将修复错误#366作为一个单元发布。 Redmine,trac,fogbugz,bugzilla,tfs,都很好。 I find the best solution to use a higher level tool to group revisions together and track c ...
-
忽略已经提交到Git存储库的文件(Ignore files that have already been committed to a Git repository [duplicate])[2023-07-28]
要解除已经添加/初始化到您的存储库的单个文件, 即停止跟踪文件,但不从系统中删除该文件,请使用: git rm --cached filename 要解除现在在.gitignore 每个文件: 首先提交任何未完成的代码更改 ,然后运行以下命令: git rm -r --cached . 这将从索引 (暂存区域)中删除任何已更改的文件,然后运行: git add . 提交: git commit -m ".gitignore is now working" 要撤消git rm --cached file ... -
Bazaar:在本地忽略文件但不在中央存储库中?(Bazaar: Ignoring files locally but not in centralized repository?)[2022-03-21]
目前看来不可能直接执行这样的任务。 但是,它已被添加到bzr问题跟踪器中的心愿单中。 At the moment it seems not to be possible to perform such a task directly. It is, however, already added to the wishlist in bzr issue tracker. -
是否要使用gitrepo2文件替换遥控器中的所有项目? 如果是这样,您需要提交新项目中的所有文件(gitrepo2)并通过执行以下命令强制推入旧远程: git push -f 这将使用本地历史记录删除遥控器中的先前历史记录。 但我不确定这是你想要做的。 另一方面,如果要删除整个本地历史记录,只需删除.git目录,然后通过运行(在项目文件夹中)启动新的存储库: rm -r .git/ git init git remote add origin remote-url-here 并开始做你的新提交。 但我不 ...
-
您可以使用下面的解决方案。 Git会检查远程,看看提交是否存在。 如果找到一个提交,那么你会得到提交,从那里我们只是得到行数。 如果行数为0,则不提交提交 git log HEAD --pretty=oneline --not --remotes -- path | wc -l 例 git log HEAD --pretty=oneline --not --remotes -- src/A | wc -l You can use the below solution. Git will check ag ...
-
Github有一个针对这种情况的帮助部分。 你可以在这里查看。 如果它们从未存在过,那将删除它们。 如果你想保留它们,请在遵循github指南之前复制该文件。 从存储库中删除它们后,将它们添加回工作目录,然后添加,然后将它们添加到.gitignore文件中,以防止git跟踪它们。 Github has a help section for this situation. You can view it here. That will remove them if they never existed. If ...
-
什么应该提交到eclipse工作区中的存储库?(What should be committed to the repository in the eclipse workspace?)[2023-01-02]
基本上,任何文件都能帮助开发人员检查仓库并且(几乎)立即打开项目来处理它。 这应该包括至少eclipse文件,如.project , .classpath和一些IDE设置。 它们也可能是一些特定于BIRT的设置。 也可以看看: 您是否将项目文件保留在版本控制之下? 使用Eclipse时,我应该将工作区添加到源代码管理中吗? Basically, any file able to help a developer checkout the repo and (almost) immediately open ... -
只需git rm .pyc文件,并确保你的.gitignore设置为从现在开始忽略它们。 你是对的,git不会忽略已提交的文件,因为它们已被添加。 如果您热衷于不删除磁盘,请使用git rm --cached删除文件。 这只是从索引中删除它们而不从磁盘中删除。 Just git rm the .pyc files, and make sure your .gitignore is set to ignore them from now on. You are correct that git will no ...