Error[8]: Undefined offset: 4, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我使用Realm数据库在 swift中做新闻应用程序.在我的数据库中有相同的新闻类别.如何从Realm数据库中获取独特的价值? 我用主键 class News: Object { dynamic var newsID: String = "" dynamic var newsTitle: String = "" dynamic var newsFullText: String = "" 我使用Realm数据库在 swift中做新闻应用程序.在我的数据库中有相同的新闻类别.如何从Realm数据库中获取独特的价值?
我用主键
class News: Object { dynamic var newsID: String = "" dynamic var newsTitle: String = "" dynamic var newsFullText: String = "" dynamic var newsImage: String = "" dynamic var newsautor: String = "" dynamic var newsCommentCount: String = "" dynamic var newsSeenCount: String = "" dynamic var newsDate: String = "" dynamic var newscategory: String = ""   overrIDe static func primaryKey() -> String? {    return "newsID"   }}

我试着去

let realm = try! Realm()let menuname = realm.objects(News)for i in menuname.filter("newscategory") {nameLabel.text = i.newscategory}

但这不起作用.

从Realm 3.10开始,现在可以

Add Results.distinct(by:) / -[RLMResults
distinctResultsUsingkeypaths:],which return a Results containing only
objects with unique values at the given key paths.

旧的回应 – 在Realm 3.10之前

现在还不可能从Realm查询中获得“独特”的功能(跟踪未解决的问题here)

但是,我在上面提到的主题中提出了一些解决方法(请通过用户apocolipse阅读它以获得完整的上下文):

// query all userslet allUsers = Realm().objects(User)// Map out the user typeslet allTypes = map(allUsers) { 
let distinctTypes = Set(Realm().objects(User).valueForKey("type") as! [String])
.type }// Fun part: start with empty array [],add in element to reduced array if its not already in,else add empty arraylet distinctTypes = reduce(allTypes,[]) { [+++] + (!contains([+++],) ? [] : [] )

或者更好的是,使用Sets(通过用户jpsim)的不同方法:

[+++]

显然,变通方法不如直接数据库查询有效,因此请谨慎使用(并在实际负载下进行测试).

总结

以上是内存溢出为你收集整理的如何在swift中从Realm数据库中获取唯一值全部内容,希望文章能够帮你解决如何在swift中从Realm数据库中获取唯一值所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 5, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我使用Realm数据库在 swift中做新闻应用程序.在我的数据库中有相同的新闻类别.如何从Realm数据库中获取独特的价值? 我用主键 class News: Object { dynamic var newsID: String = "" dynamic var newsTitle: String = "" dynamic var newsFullText: String = "" 我使用Realm数据库在 swift中做新闻应用程序.在我的数据库中有相同的新闻类别.如何从Realm数据库中获取独特的价值?
我用主键
class News: Object { dynamic var newsID: String = "" dynamic var newsTitle: String = "" dynamic var newsFullText: String = "" dynamic var newsImage: String = "" dynamic var newsautor: String = "" dynamic var newsCommentCount: String = "" dynamic var newsSeenCount: String = "" dynamic var newsDate: String = "" dynamic var newscategory: String = ""   overrIDe static func primaryKey() -> String? {    return "newsID"   }}

我试着去

let realm = try! Realm()let menuname = realm.objects(News)for i in menuname.filter("newscategory") {nameLabel.text = i.newscategory}

但这不起作用.

从Realm 3.10开始,现在可以

Add Results.distinct(by:) / -[RLMResults
distinctResultsUsingkeypaths:],which return a Results containing only
objects with unique values at the given key paths.

旧的回应 – 在Realm 3.10之前

现在还不可能从Realm查询中获得“独特”的功能(跟踪未解决的问题here)

但是,我在上面提到的主题中提出了一些解决方法(请通过用户apocolipse阅读它以获得完整的上下文):

// query all userslet allUsers = Realm().objects(User)// Map out the user typeslet allTypes = map(allUsers) { 
let distinctTypes = Set(Realm().objects(User).valueForKey("type") as! [String])
.type }// Fun part: start with empty array [],add in element to reduced array if its not already in,else add empty arraylet distinctTypes = reduce(allTypes,[]) { + (!contains([+++],) ? [] : [] )

或者更好的是,使用Sets(通过用户jpsim)的不同方法:

[+++]

显然,变通方法不如直接数据库查询有效,因此请谨慎使用(并在实际负载下进行测试).

总结

以上是内存溢出为你收集整理的如何在swift中从Realm数据库中获取唯一值全部内容,希望文章能够帮你解决如何在swift中从Realm数据库中获取唯一值所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 6, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我使用Realm数据库在 swift中做新闻应用程序.在我的数据库中有相同的新闻类别.如何从Realm数据库中获取独特的价值? 我用主键 class News: Object { dynamic var newsID: String = "" dynamic var newsTitle: String = "" dynamic var newsFullText: String = "" 我使用Realm数据库在 swift中做新闻应用程序.在我的数据库中有相同的新闻类别.如何从Realm数据库中获取独特的价值?
我用主键
class News: Object { dynamic var newsID: String = "" dynamic var newsTitle: String = "" dynamic var newsFullText: String = "" dynamic var newsImage: String = "" dynamic var newsautor: String = "" dynamic var newsCommentCount: String = "" dynamic var newsSeenCount: String = "" dynamic var newsDate: String = "" dynamic var newscategory: String = ""   overrIDe static func primaryKey() -> String? {    return "newsID"   }}

我试着去

let realm = try! Realm()let menuname = realm.objects(News)for i in menuname.filter("newscategory") {nameLabel.text = i.newscategory}

但这不起作用.

从Realm 3.10开始,现在可以

Add Results.distinct(by:) / -[RLMResults
distinctResultsUsingkeypaths:],which return a Results containing only
objects with unique values at the given key paths.

旧的回应 – 在Realm 3.10之前

现在还不可能从Realm查询中获得“独特”的功能(跟踪未解决的问题here)

但是,我在上面提到的主题中提出了一些解决方法(请通过用户apocolipse阅读它以获得完整的上下文):

// query all userslet allUsers = Realm().objects(User)// Map out the user typeslet allTypes = map(allUsers) { 
let distinctTypes = Set(Realm().objects(User).valueForKey("type") as! [String])
.type }// Fun part: start with empty array [],add in element to reduced array if its not already in,else add empty arraylet distinctTypes = reduce(allTypes,[]) { + (!contains(,) ? [] : [] )

或者更好的是,使用Sets(通过用户jpsim)的不同方法:

[+++]

显然,变通方法不如直接数据库查询有效,因此请谨慎使用(并在实际负载下进行测试).

总结

以上是内存溢出为你收集整理的如何在swift中从Realm数据库中获取唯一值全部内容,希望文章能够帮你解决如何在swift中从Realm数据库中获取唯一值所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
如何在swift中从Realm数据库中获取唯一值_app_内存溢出

如何在swift中从Realm数据库中获取唯一值

如何在swift中从Realm数据库中获取唯一值,第1张

概述我使用Realm数据库在 swift中做新闻应用程序.在我的数据库中有相同的新闻类别.如何从Realm数据库中获取独特的价值? 我用主键 class News: Object { dynamic var newsID: String = "" dynamic var newsTitle: String = "" dynamic var newsFullText: String = "" 我使用Realm数据库在 swift中做新闻应用程序.在我的数据库中有相同的新闻类别.如何从Realm数据库中获取独特的价值?
我用主键
class News: Object { dynamic var newsID: String = "" dynamic var newsTitle: String = "" dynamic var newsFullText: String = "" dynamic var newsImage: String = "" dynamic var newsautor: String = "" dynamic var newsCommentCount: String = "" dynamic var newsSeenCount: String = "" dynamic var newsDate: String = "" dynamic var newscategory: String = ""   overrIDe static func primaryKey() -> String? {    return "newsID"   }}

我试着去

let realm = try! Realm()let menuname = realm.objects(News)for i in menuname.filter("newscategory") {nameLabel.text = i.newscategory}

但这不起作用.

从Realm 3.10开始,现在可以

Add Results.distinct(by:) / -[RLMResults
distinctResultsUsingkeypaths:],which return a Results containing only
objects with unique values at the given key paths.

旧的回应 – 在Realm 3.10之前

现在还不可能从Realm查询中获得“独特”的功能(跟踪未解决的问题here)

但是,我在上面提到的主题中提出了一些解决方法(请通过用户apocolipse阅读它以获得完整的上下文):

// query all userslet allUsers = Realm().objects(User)// Map out the user typeslet allTypes = map(allUsers) { 
let distinctTypes = Set(Realm().objects(User).valueForKey("type") as! [String])
.type }// Fun part: start with empty array [],add in element to reduced array if its not already in,else add empty arraylet distinctTypes = reduce(allTypes,[]) { + (!contains(,) ? [] : [] )

或者更好的是,使用Sets(通过用户jpsim)的不同方法:

显然,变通方法不如直接数据库查询有效,因此请谨慎使用(并在实际负载下进行测试).

总结

以上是内存溢出为你收集整理的如何在swift中从Realm数据库中获取唯一值全部内容,希望文章能够帮你解决如何在swift中从Realm数据库中获取唯一值所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1043873.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存