SwiftUI error All In One

Instance member xxx cannot be used on type yyy

Instance member 'game' cannot be used on type 'ContentView_Previews'


  1. //
  2. // ContentView.swift
  3. // MemorizeGame
  4. //
  5. // Created by 夏凌晨 on 2020/10/28.
  6. // Copyright 2020 xgqfrms. All rights reserved.
  7. //
  8. // viewModel
  9. import SwiftUI
  10. // some View,返回任意类型的 View, 自动推断 View 类型
  11. // Identifiable
  12. struct ContentView: View {
  13. var viewModel: EmojiMemoryGame
  14. var body: some View {
  15. HStack {
  16. // ForEach(0..<4) { index in
  17. ForEach(viewModel.cards) { card in
  18. // print("index \(index)")
  19. CardView(card: card).onTapGesture {
  20. // self
  21. self.viewModel.choose(card: card)
  22. }
  23. // CardView(isFaceUp: (index % 2 == 0))
  24. }
  25. }
  26. // HStack {
  27. // CardView(isFaceUp: true)
  28. // CardView(isFaceUp: false)
  29. // CardView(isFaceUp: true)
  30. // CardView(isFaceUp: false)
  31. // }
  32. }
  33. }
  34. struct CardView: View {
  35. var card: MemoryGame<String>.Card
  36. // var isFaceUp: Bool
  37. // var isFaceUp: Bool = false
  38. var body: some View {
  39. ZStack {
  40. if card.isFaceUp {
  41. RoundedRectangle(cornerRadius: 10.0).fill(Color.white)
  42. RoundedRectangle(cornerRadius: 10.0).stroke(lineWidth: 3.0)
  43. Text(card.content).font(.largeTitle)
  44. // Text("").font(.largeTitle)
  45. } else {
  46. RoundedRectangle(cornerRadius: 10.0).fill(Color.orange)
  47. }
  48. }.padding()
  49. }
  50. }
  51. // PreviewProvider 仅用于预览,代码在项目中没有实际的意义
  52. struct ContentView_Previews: PreviewProvider {
  53. let game = EmojiMemoryGame()
  54. static var previews: some View {
  55. ContentView(viewModel: game)
  56. }
  57. }

change file name bug

  1. old MemorizeGame
  1. //
  2. // ContentView.swift
  3. // MemorizeGame
  1. new MemoryGame

  1. //
  2. // ContentView.swift
  3. // MemoryGame

refs



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


SwiftUI error All In One的更多相关文章

  1. SwiftUI学习(一)

    总览 如果你想要入门 SwiftUI 的使用,那 Apple 这次给出的官方教程绝对给力.这个教程提供了非常详尽的步骤和说明,网页的交互也是一流,是觉得值得看和动手学习的参考. 不过,SwiftUI ...

  2. 解析SwiftUI布局细节(三)地图的基本操作

    前言 前面的几篇文章总结了怎样用 SwiftUI 搭建基本框架时候的一些注意点(和这篇文章在相同的分类里面,有需要了可以点进去看看),这篇文章要总结的东西是用地图数据处理结合来说的,通过这篇文章我们能 ...

  3. Mediaplayer error (-19,0)

    Android MediaPlayer 发生 error (-19,0) 错误解决方法. 引起原因:由于多次实例化MediaPlayer.start() 进行播放操作引起的.由于没有及时释放内存资源导 ...

  4. 4.Android 打包时出现的Android Export aborted because fatal error were founds [closed]

    Android 程序开发完成后,如果要发布到互联网上供别人使用,就需要将自己的程序打包成Android 安装包文件(Android Package,APK),其扩展名为.apk.使用run as 也能 ...

  5. myeclipse 内存不够用报错PermGen space 和 An internal error has occurred.

    最近项目中又增加了新的模块,项目的代码又多了不少.运行的时候总是报如下错误 Exception in thread "http-apr-80-exec-6" java.lang.O ...

  6. error C4430:missing type specifier 解决错误

    错误    3    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ...

  7. PhpStorm和WAMP配置调试参数,问题描述Error. Interpreter is not specified or invalid. Press “Fix” to edit your project configuration.

    PhpStorm和WAMP配置调试参数 问题描述: Error. Interpreter is not specified or invalid. Press “Fix” to edit your p ...

  8. Visual Studio:error MSB8020(搬运)

    状况如下: error MSB8020: The builds tools for v120 (Platform Toolset = 'v120') cannot be found. To build ...

  9. 转:ORA-15186: ASMLIB error function = [asm_open], error = [1], 2009-05-24 13:57:38

    转:ORA-15186: ASMLIB error function = [asm_open], error = [1], 2009-05-24 13:57:38http://space.itpub. ...

随机推荐

  1. Vue基础之生命周期函数[残缺版]!

    Vue基础之生命周期函数[残缺版]! 为什么说是残缺版呢?! 因为有一些周期函数我并没有学到!所以是残缺版! 01 beforeCreate //在实例初始化之后,数据观测 (data observe ...

  2. HTML Standard系列:Event loop、requestIdleCallback 和 requestAnimationFrame

    HTML Standard系列:Event loop.requestIdleCallback 和 requestAnimationFrame - 掘金 https://juejin.im/post/5 ...

  3. 【Soul网关探秘】http数据同步-Web端处理变更通知

    个人知识库 引言 上一篇,梳理http 数据同步策略的变更通知机制,本篇开始探究配置变更通知到达后, soul-web 端的处理响应. 不同数据变更的通知机制应当是一致的,故本篇以 selector ...

  4. cpdd 坐标:SD

    updata on:2021.1.17 闲来无事继续鸽 性别:男 先鸽一会想起来再填/se

  5. linux下安装 zookeeper-3.4.9并搭建集群环境

    本文主要记录作者在实践过程中实现在centos7环境下安装zookeeper并搭建集群的详细步骤,关于zookeeper本文将不做详细介绍,安装步骤详情如下: 前提准备:3台linux服务器(因为zo ...

  6. 查看Linux用的桌面是GNOME、KDE或者其他(转)

    http://superuser.com/questions/96151/how-do-i-check-whether-i-am-using-kde-or-gnome 1) pgrep -l &quo ...

  7. HTML学习速记

    HTML结构导图 先看HTML结构示意图 本文主要讲解HTML当中的一些html标签,css样式,javascript方法 html html的标签有各式各样的数不胜数,但是常用的并不多,总结下我目前 ...

  8. 一次小模块的使用过程-LC12S无线模块介绍

    前言: 最近帮人做了个小设备,使用了无线模块.触摸芯片,主要功能就是把触摸按键的信号无线传到控制继电器输出,MCU是STM8系列的芯片,其中使用过程中调试无线模块LC21S觉得挺好用的,就写了这篇文章 ...

  9. linux虚拟摄像头vivid配置

    总述    最近在看摄像头驱动,需要配置虚拟摄像头的驱动,但是教程里面是linux2.6内核的,实际电脑的是Ubuntu16,内核是linux4.15版本,从2.6到4.15内核好多文件发生了变化,所 ...

  10. A - A Supermarket (贪心, 并查集)

    超市里有n个产品要卖,每个产品都有一个截至时间dx(从开始卖时算起),只有在这个截至时间之前才能卖出并且获得率润dy. 有多个产品,所有可以有不同的卖出顺序,每卖一个产品要占用1个单位的时间,问最多能 ...