Coder Social home page Coder Social logo

awesomeswift's Introduction

AwesomeSwift -- SwiftUI 综合示例、样板工程

1、简介

该项目是在阅读了多个开源项目源码之后沉淀而成,用来演示 SwiftUI 的控件和各种功能组件的使用,同时包含了实际开发过程中可能使用到的各种必备的组件,比如 Lottie、RSwift、崩溃统计等等,适合想要学习 Swift 开发的的新手同学。

2、技术示范

该项目支持最低版本 iOS 为 14,使用 CocoaPods 作为构建工具。下面是范例清单。

2.1 SwiftUI 内置控件

  • Text 的示范:TextDemoView
    • Text:普通文本
    • Link:可以点击的链接
  • 按钮的示范:ButtonDemoView
    • Button:常规按钮以及常用的背景实现示范
    • Toggle:开闭按钮
    • Slider:滑块按钮
    • Stepper:步进器
    • NavigationLink:跳转按钮
  • 输入框的示范:TextFieldDemoView
    • TextField:单行输入
    • TextEditor:多行输入
    • SecureField:密码输入
  • 图片控件 Image 的示例:ImageDemoView
    • Image:使用 UIImage、系统内置图片、缩放技巧
    • 自定义形状:LinearGradient、RoundedRectangle、Capsule 和 Circle
  • 表单的示例:FormDemoView
  • 对话框和弹出:PopupDemoView
    • ActionSheet:底部弹出的标准对话框
    • Alert:中间弹出的标准对话框
    • Popover:可自定义弹出浮层,但是会让底部对话框缩小
    • Picker:局部弹出的列表选择框,支持多种样式
    • DatePicker:日期和时间选择
  • 动画的示例:AnimationDemoView
    • DragGesture:手势拖动
    • withAnimation:淡入淡出等效果
    • simultaneousGesture:持续手势处理
    • highPriorityGesture:高优先级手势
    • ViewModifier:自定义变换
  • 布局示例:LayoutDemoView
    • 布局控件:ScrollView、HStack、VStack 和 ZStack
    • alignment:对齐属性
    • multilineTextAlignment:多行文本对齐属性
    • alignmentGuide:对齐属性微调
  • SwiftUI 中使用 UIKit 控件示范:SegmentedViewDemo
    • 继承 UIViewRepresentable 并实现 makeCoordinator、makeUIView 和 updateUIView 三个方法

2.2 开发必备的非官方控件

2.3 常用页面结构示例

2.4 常用业务和功能模块

2.5 数据存储和数据交互

数据存储

数据交互

2.6 环境和开发框架

除了上述控件和页面框架等基本单元,作为一个成熟的产品,对应用的稳定性和开发的高效也是有要求的,这要求我们对开发环境进行基础的设置。所以,这里列举的是一些必要的可以提升开发效率和应用稳定性的工具。

  • firebase-ios-sdk:应用崩溃监控,用来上报程序崩溃日志和进行简单的用户统计
    • 集成说明:Get started with Firebase Crashlytics
    • Step 1: 按照官网的说明,添加 Firebase Crashlytics 依赖
    • Step 2: 修改 Build Settings,输出 dSYM 文件
    • Step 3: 修改 Build Phase,添加上传 dSYM 文件的逻辑
    • Step 4: 添加崩溃,然后测试,测试的时候需要构建完成并 Stop 再测试,因为处于 debug 状态的时候,xcode 会拦截崩溃
  • R.swift:用来以类似于 Android 的 R 文件的方式引用项目里的资源,比直接使用字符串应用的方式不容易出错
  • Then:语法躺,类似于 Kotlin 的 apply 的效果,但是似乎只对 UIKit 有效
  • CocoaPods:项目的构建工具和依赖管理工具
    • 创建 Podfile 文件
    • 执行 pod install 命令
  • SwiftPackageManager:项目的依赖管理工具

2.7 综合示例

WanAndroid 示例工程

  • 项目地址:WanAndroid
  • 该项目基于 Alamofire 实现网络请求
  • 该项目基于 HandyJSON 实现 JSON 数据解析
  • 该项目基于 Kingfisher 实现网络图片加载
  • 该项目基于 MVVM 设计和开发

License

Copyright (c) 2022-present WiSH

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

awesomeswift's People

Contributors

shouheng88 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.