SwiftUI error All In One
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


- old MemorizeGame
//
// ContentView.swift
// MemorizeGame
- new MemoryGame
//
// ContentView.swift
// MemoryGame
refs
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
SwiftUI error All In One的更多相关文章
- SwiftUI学习(一)
总览 如果你想要入门 SwiftUI 的使用,那 Apple 这次给出的官方教程绝对给力.这个教程提供了非常详尽的步骤和说明,网页的交互也是一流,是觉得值得看和动手学习的参考. 不过,SwiftUI ...
- 解析SwiftUI布局细节(三)地图的基本操作
前言 前面的几篇文章总结了怎样用 SwiftUI 搭建基本框架时候的一些注意点(和这篇文章在相同的分类里面,有需要了可以点进去看看),这篇文章要总结的东西是用地图数据处理结合来说的,通过这篇文章我们能 ...
- Mediaplayer error (-19,0)
Android MediaPlayer 发生 error (-19,0) 错误解决方法. 引起原因:由于多次实例化MediaPlayer.start() 进行播放操作引起的.由于没有及时释放内存资源导 ...
- 4.Android 打包时出现的Android Export aborted because fatal error were founds [closed]
Android 程序开发完成后,如果要发布到互联网上供别人使用,就需要将自己的程序打包成Android 安装包文件(Android Package,APK),其扩展名为.apk.使用run as 也能 ...
- myeclipse 内存不够用报错PermGen space 和 An internal error has occurred.
最近项目中又增加了新的模块,项目的代码又多了不少.运行的时候总是报如下错误 Exception in thread "http-apr-80-exec-6" java.lang.O ...
- error C4430:missing type specifier 解决错误
错误 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ...
- 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 ...
- Visual Studio:error MSB8020(搬运)
状况如下: error MSB8020: The builds tools for v120 (Platform Toolset = 'v120') cannot be found. To build ...
- 转: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. ...
随机推荐
- Linux下运行java报错:Error: Could not find or load main class SocketIOPropertites
[root@node01 testfileio]# javac SocketIOPropertites.java && java Soc ketIOPropertitesError: ...
- Spring Data JPA基本增删改查和JPQL查询(含完整代码和视频连接)
问题:SpringDataJPA怎么使用? 一.考察目标 主要考核SpringDataJPA的用法 二.题目分析 spring data jpa 的使用步骤(下面有具体实现细节) 1.创建maven工 ...
- Architecture and design 洋葱 中间件 装饰器
Go kit - Frequently asked questions https://gokit.io/faq/ Architecture and design Introduction - Und ...
- You shouldn't use *any* general-purpose hash function for user passwords, not BLAKE2, and not MD5, SHA-1, SHA-256, or SHA-3
hashlib - Secure hashes and message digests - Python 3.8.3 documentation https://docs.python.org/3.8 ...
- Java——break,continue,return语句
break语句: break:用于改变程序控制流 用于do-while.while.for中时,可跳出循环而执行循环后面的语句. break的作用:终止当前循环语句的执行. break还可以用来终止s ...
- Session (简介、、相关方法、流程解析、登录验证)
Session简介 Session的由来 Cookie虽然在一定程度上解决了"保持状态"的需求,但是由于Cookie本身最大支持4096字节,以及Cookie本身保存在客户端,可能 ...
- netty写Echo Server & Client完整步骤教程(图文)
1.创建Maven工程 1.1 父节点的pom.xml代码(root pom文件) 1 <?xml version="1.0" encoding="UTF-8&qu ...
- python爬虫selenium相关
首先上很好用的selenium中文文档,基本上所有问题都能通过阅读此文档解决.可惜好像没找到翻译者名称. https://python-selenium-zh.readthedocs.io/zh_CN ...
- 设计模式(三)——Java工厂方法模式
工厂方法模式 1 看一个新的需求 披萨项目新的需求:客户在点披萨时,可以点不同口味的披萨,比如 北京的奶酪 pizza.北京的胡椒 pizza 或者是伦敦的奶酪 pizza.伦敦的胡椒 pizza. ...
- Codeforces Round #664 (Div. 2) D. Boboniu Chats with Du
传送门:cf1395D 题意 给定一个长度为n的数组a[i]为当天说话的有趣值,如果a[i]>m,那么在 i 之后有d天不能说话.否则可以每天都说话.找到一个排列使得n天有趣值总和最大,问有趣值 ...