SwiftUI error All In One

Instance member xxx cannot be used on type yyy

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


//
// ContentView.swift
// MemorizeGame
//
// Created by 夏凌晨 on 2020/10/28.
// Copyright 2020 xgqfrms. All rights reserved.
// // viewModel
import SwiftUI // some View,返回任意类型的 View, 自动推断 View 类型
// Identifiable
struct ContentView: View {
var viewModel: EmojiMemoryGame var body: some View {
HStack {
// ForEach(0..<4) { index in
ForEach(viewModel.cards) { card in
// print("index \(index)")
CardView(card: card).onTapGesture {
// self
self.viewModel.choose(card: card)
}
// CardView(isFaceUp: (index % 2 == 0))
}
}
// HStack {
// CardView(isFaceUp: true)
// CardView(isFaceUp: false)
// CardView(isFaceUp: true)
// CardView(isFaceUp: false)
// }
}
} struct CardView: View {
var card: MemoryGame<String>.Card
// var isFaceUp: Bool
// var isFaceUp: Bool = false
var body: some View {
ZStack {
if card.isFaceUp {
RoundedRectangle(cornerRadius: 10.0).fill(Color.white)
RoundedRectangle(cornerRadius: 10.0).stroke(lineWidth: 3.0)
Text(card.content).font(.largeTitle)
// Text("").font(.largeTitle)
} else {
RoundedRectangle(cornerRadius: 10.0).fill(Color.orange)
}
}.padding()
}
} // PreviewProvider 仅用于预览,代码在项目中没有实际的意义
struct ContentView_Previews: PreviewProvider {
let game = EmojiMemoryGame()
static var previews: some View {
ContentView(viewModel: game)
}
}

change file name bug

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

//
// ContentView.swift
// 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. shell批量解压源码包

    有时候部署环境有很多安装包,如果一个一个地解压缩实在太麻烦了,可以用shell批量进行解压缩.命令如下: [root@localhost ~]# vi tar.sh #! /bin/bash #标称是 ...

  2. 解决Linux下mysql区分大小写的问题

    1.查看lower_case_table_names的值,0代表区分大小写,1代表不区分大小写. 通过命令:SHOW VARIABLES LIKE 'lower%'; 1. 解决方法 以root用户登 ...

  3. Mac 禁用动画

    # opening and closing windows and popovers defaults write -g NSAutomaticWindowAnimationsEnabled -boo ...

  4. 下面给出一个child-parent的表格,要求挖掘其中的父子辈关系,给出祖孙辈关系的表格。

    package org.apache.hadoop.examples; import java.util.HashMap; import java.io.IOException; import jav ...

  5. How to kill go routine?

    How to kill go routine? https://stackoverflow.com/questions/37997608/kill-a-method-in-an-infinite-lo ...

  6. scala/java等其他语言从CSV文件中读取数据,使用逗号','分割可能会出现的问题

    众所周知,csv文件默认以逗号","分割数据,那么在scala命令行里查询的数据: 可以看见,字段里就包含了逗号",",那接下来切割的时候,这本应该作为一个整体 ...

  7. 接口鉴权之sign签名校验与JWT验证

    需求描述: 项目里的几个Webapi接口需要进行鉴权,同接口可被小程序或网页调用,小程序里没有用户登录的概念,网页里有用户登录的概念,对于调用方来源是小程序的情况下进行放权,其他情况下需要有身份验证. ...

  8. MySQL下载地址与Centos7安装MySQL以及启动问题排查

    目录 一.MySQL国内镜像下载 二.国内镜像相关站点 三.Centos7安装MySQL5.7 1. 下载并解压至/usr/local 2. 配置信息 3. 用户及用户组管理(提高安全) 4. 初始化 ...

  9. 高性能数据导入方案&表过滤器&一对多支持筛选- .NET SqlSugar ORM

    一.数据导入有哪些难题 1.数据分类 你需要将 插入.更新.忽略不计.错误数据 等进么分类汇总,最后返回给客户,如果没有很好的设计想把这些操作一步到位非常的难 2.高性能 对于插入或者更新 肯定不能单 ...

  10. linux 下解决mysql root 权限无法远程连接问题

    问题描述:MySQL数据库安装成功后,在服务器本地可以连接成功,但是使用工具navicat无法进行远程连接,如图: 原因:MySQL默认只允许root帐户在本地登录,如果要在其它机器上连接mysql, ...