| |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
-> 移动开发 -> Swift Programming-Note 05-MVVM -> 正文阅读 |
|
[移动开发]Swift Programming-Note 05-MVVM |
Lecture03:Mdel-View-ViewModel (MVVM)????????A "coding organizing" architectural design paradigm. ????????Must be adhered to for SwiftUI to work. ????????It is different from MVC (Model View Controller) that UIKit (old-style iOS) uses. ?
?
Generics
We may want to manipulate data structures that we are "type agnostic" about. In other words, we don't know what type something is and we don't care. But Swift is a strongly-typed language, so we don't use variables and such that are "untyped". So how do we specify the type of soemthing when we don't vare what type it is? We use a "don't care" type (we calll this feature "genetics")--范型 How Array uses a "don't care" type Array's declearation looks something like this ...
The type of the argument to append is Element. A "don't care: type. Array's implementation of append knows nothing about that argument and it does not care. Element is not any known struct or class or protocal, it's just a placeholder for a type. The code for using an Array looks something like this...
When someone uses Array, that's when Element gets determined(by Array<Int>) Note that Array has to let the world know the names of all of its "don't care" types in its API. It does this with the < > notation on its struct declaration Array<Element> above. That's how users of Array know that they have to say what type Element actually is.
It is perfectly legal to have multiple "don't care" types in the above (e.g. <Element, foo>)
I willl often refer to these types like element in Array as a "don't care" type If you ask Array what type its elements are, it will say "I don't care". But its actual name is Type Parameter. Other languages most of you may know (e.g. Java) hava a similar feature. However, Swift combines this with protocols to take it all to? the next level. We'll talk about that next week! Functions as Types
You can declare a variable (or parameter to a func or whatever) to be of type "function". The syntax for this includes the types of the arguments and return value. You can do this anywhere any other type is allowed. Examples ...
All off the above a just types. No different than Bool or View or Array<Int>. All are types
Example ...
Closures 闭包 It's so common to pass functions around that we are very often "inlining" them. We call such an inlined function a "closure" and there's special language support for it. We'll cover this in the demo and again later in the quarter. Remember that we are mostly doing "functional programming" in SwiftUI. As the very name implies, "funcitons as types" is a very important concept in Swift. Very.
Now that we know about MVVM, let's implement it in our Memorize application In doing so, we'll see a lot of what we just talked about ... We're going to use the special init function (in both our Model and our ViewModel) We're going to use generics in our implementation of our Model We're going to use a function as a type in our Model We're going to see a class for the first time(our ViewModel will be a class) We're going to implement an "Intent" in our MVVM And finally, we will make our UI"reactive" through our MVVM design Whew! Let's get started ... |
|
移动开发 最新文章 |
Vue3装载axios和element-ui |
android adb cmd |
【xcode】Xcode常用快捷键与技巧 |
Android开发中的线程池使用 |
Java 和 Android 的 Base64 |
Android 测试文字编码格式 |
微信小程序支付 |
安卓权限记录 |
知乎之自动养号 |
【Android Jetpack】DataStore |
|
上一篇文章 下一篇文章 查看所有文章 |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 | -2024/11/24 14:56:31- |
|
网站联系: qq:121756557 email:121756557@qq.com IT数码 |