小编rod*_*elp的帖子

如何使用 Amplify iOS (AppSync) 存储关系(一对多或多对一)数据?

今天检查了一些放大文档(我知道这个文档说它是iOS场景中的预览)但我遇到了一个障碍。

假设

  1. 在我的 iOS 项目中正确配置了 Amplify。我可以将数据推送到Person并查询Amplify.API
  2. 该架构已定义为:
type Person @model {
  id: ID!
  name: String!
  possessions: [Thing] # list of things this person owns.
    @connection(keyName: "byPerson", fields: ["id"])
}

type Thing @model
           @key(name: "byPerson", fields: ["personId"]) {

  id: ID!
  name: String!
  personId: ID!
  ownerOfThings: Person # defining the 'belongsTo' property.
    @connection(fields: ["personId"])
}
Run Code Online (Sandbox Code Playgroud)

这将生成以下代码:

type Person @model {
  id: ID!
  name: String!
  possessions: [Thing] # list of things this person owns.
    @connection(keyName: "byPerson", …
Run Code Online (Sandbox Code Playgroud)

ios swift graphql aws-amplify amplify-ios

9
推荐指数
0
解决办法
1727
查看次数

如何使用C#中的TPL任务将工作编组到主线程上而不会导致死锁?

我正在编写一个消耗资源的库,无论出于什么原因,API的设计方式是在不同的线程上引发事件,但是必须在主线程上完成API的调用.

假设我尝试使用的API被定义为(我将省略事件定义):

public sealed class DodgyService
{
    public void MethodThatHasToBeCalledOnTheMainThread() { ... }
}
Run Code Online (Sandbox Code Playgroud)

为了使用这个API,我在我的库中添加了一个名为Service(Yup,非常原始名称)的服务,它将创建一个新任务(当我指定一个已经创建的TaskScheduler时,它将在主线程上运行SynchronizationContext).

这是我的实现:

public class Service
{
  private readonly TaskFactory _taskFactory;
  private readonly TaskScheduler _mainThreadScheduler;

  public Service(TaskFactory taskFactory, TaskScheduler mainThreadScheduler)
  {
      _taskFactory = taskFactory;
      _mainThreadScheduler = mainThreadScheduler;
  }

  // Assume this method can be called from any thread.
  // In this sample is called by the main thread but most of the time
  // the caller will be running on a background thread.
  public Task …
Run Code Online (Sandbox Code Playgroud)

.net c# multithreading task-parallel-library

7
推荐指数
2
解决办法
1457
查看次数

如何在反应原生(声明性)中将多个动画链接在一起?

我的问题很具体:

如何链接两个动画,以便将项目从 X 移动到 Y,然后从 Y 移动到 Z?

我有一个视图,我想从位置 (x,y) 到 (x+a, y+b) 设置动画,然后让它“悬停”在那里。我以为动画会从它停止的点继续,但事实证明我错了......当它执行循环时,它从初始值(0,0)而不是最后一个位置重新开始。

// this is in my index.js
class App extends Component {
  constructor(props) {
    super(props);
    this.translateValue = new Animated.ValueXY({x: 0, y: 0});
  }

  componentDidMount() {
    Animated.sequence([
      Animated.timing(this.translateValue,
        { toValue: { x: 30, y: 30 }, duration: 1000, easing: Easing.linear }),
      Animated.loop(
        Animated.sequence([
          Animated.timing(this.translateValue,
            { toValue: { x: 30, y: 20 }, duration: 1000, easing: Easing.linear }),
          Animated.timing(this.translateValue,
           { toValue: { x: 30, y: 30 }, duration: 1000, …
Run Code Online (Sandbox Code Playgroud)

javascript animation react-native

5
推荐指数
1
解决办法
6161
查看次数

Swift Combine:在可观察对象中使用计时器发布者

在这个问题被标记为另一个问题的重复之前,我试图了解发布者的工作方式,因为它以我不期望的方式行事。

使用与前面提到的问题的答案相同的示例:

// Let's define the view model with my view...
import Combine
import SwiftUI

class TimerViewModel: ObservableObject {
  private let cancellable: AnyCancellable?

  let intervalPublisher = Timer.TimerPublisher(
                            interval: 1.0, 
                            runLoop: .main, 
                            mode: .default)

  init() {
    self.cancellable = timerPublisher.connect() as? AnyCancellable
  }

  deinit {
    self.cancellable?.cancel()
  }
}

struct Clock : View {
  @EnvironmentObject var viewModel: TimerViewModel
  @State private var currentTime: String = "Initial"


  var body: some View {
    VStack {
      Text(currentTime)
    }
    .onReceive(timer.intervalPublisher) { newTime in
      self.currentTime = String(describing: …
Run Code Online (Sandbox Code Playgroud)

xcode swift swiftui xcode11 combine

4
推荐指数
1
解决办法
6008
查看次数