- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在优化我的应用程序。我的表结构简化如下:
主类别
姓名
位置
有子类别
子类别
姓名
位置
属于MainCategory
现在,如果用户在第一个 View Controller 中选择一个主要类别,他将转到下一个显示特定主要类别的所有子类别。到目前为止,代码如下:
- (void)setupFetchedResultsController
{
NSError *error = nil;
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"SubCategory"];
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"position" ascending:YES]];
[self.mainCategory.managedObjectContext executeFetchRequest:request error:&error];
request.predicate = [NSPredicate predicateWithFormat:@"belongsToMainCategory = %@", self.mainCategory];
self.fetchedResultsController = [[NSFetchedResultsController alloc]initWithFetchRequest:request
managedObjectContext:self.mainCategory.managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
}
现在我开始怀疑我是否需要这样做,因为如果我将我的数据模型设置为主要类别,我将在 mainCategory.hasSubcategories
中获得所有信息。然而这些对象是如何排序的呢?或者像我现在那样重新获取真的更容易吗?
最佳答案
我的简单建议是保留该代码。如果您访问 mainCategory.hasSubcategories
,您将拥有一个未排序的 NSSet
。所以,您需要自己订购。
在我的代码中,如果我需要像您那样做,我通常会使用这种模式。它非常简单,可以重复使用。此外,如果您担心表演,不用担心。引擎盖下的 Core Data 维护一个缓存,可让您提高检索性能。
如果你想加快速度,你还可以依赖 NSFetchRequest
类的 setRelationshipKeyPathsForPrefetching
方法。
关于iOS 核心数据 : Refetch of subcategories necessary?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20815000/
我正在尝试将来自 useQuery() 的重新获取传递到上下文中,以便我可以从上下文中调用重新获取。我无法找出正确的类型,因此我要么遇到类型不匹配问题,要么 IDE 不会提示,但应用程序会因类型不匹配
我目前正在优化我的应用程序。我的表结构简化如下: 主类别 姓名 位置 有子类别 子类别 姓名 位置 属于MainCategory 现在,如果用户在第一个 View Controller 中选择一个主要
我的渲染函数 translateFileAndRefetchQuery = (urn) => { translateFile(urn); // How do I refetch dat
我正在使用 React-native 和 React-query,我想在屏幕卸载时停止自动重新获取。 目前,当我转到目标屏幕时,我会调用一个带有间隔参数的查询: const { data: missi
我有以下 apollo-graphql 客户端代码,其中我每 30 秒触发一次 graphql 查询并获取数据。 import React, { Component } from 'react'; i
这是我如何使用 MockedProvider。如何在 mocks 数组中模拟 refetch? const mocks = [{ request: { quer
在前端,我使用 ReactJS 并尝试在 ListView 中内置过滤选项。 ListView 通过发出此 graphql 查询正确地从 graphql 端点获取数据: query getVideos
我正在使用 Express 构建 GraphQL 服务器并尝试支持 Relay。 对于常规的 GraphQL 查询,我可以在 resolve 函数中处理授权。例如: var queryType = n
今天,我在 React.js 项目中遇到了 GraphQL 问题。我试图做的是在突变完成后重新获取查询。我的代码库如下 const getUserTeamQuery = useQuery(getUse
有什么不同queryClient.refetchQueries()与 const {refetch} = useQuery() 我不认为这有什么不同; 当我使用queryClient.refetchQ
这是一个很奇怪的问题。 我有一个相当简单的查询,无论我触发多少次,它在 Graphiql 中都运行得很好 但在浏览器中,当我调用 data.refetch() 时,就会出现问题。最奇怪的是,在 Chr
这是一个很奇怪的问题。 我有一个相当简单的查询,无论我触发多少次,它在 Graphiql 中都运行得很好 但在浏览器中,当我调用 data.refetch() 时,就会出现问题。最奇怪的是,在 Chr
遵循 Apollo 的重构模式 https://www.apollographql.com/docs/react/recipes/recompose.html 我创建了一个简单的 ErrorScree
(如果这个问题有点令人困惑/不精确,我很抱歉。我只是在学习高级 CoreData 用法,我不太了解术语和其他东西)。 我有一个单例 Game,它包含您在游戏过程中需要的某些数据。例如,您可以从那里访问
我的代码运行良好,但在快速引用并使用 refreshControl 进行刷新后,我在 React Native 中遇到了这个错误 TypeError - undefined 不是对象(评估“c.cur
我正在使用 PHP Codeigniter 制作一个基本的注册页面。 在注册页面上,我要求用户从一系列类别中进行选择(通过 html 元素)。这些类别存储在我的 MySQL 数据库的列表中。 我当前
我想创建一个新实体,然后聚合 FK 对象的属性,然后将它们保存到新创建的对象中。考虑在对象上填充关键字字段以插入类似 google 的搜索。 目前,我发现执行此操作的唯一方法是添加新实体,调用 con
我是一名优秀的程序员,十分优秀!