
Swift
最新Swift5博客系列精品教程
Swift基础语法及新特性、与Objective-C的异同等基础知识点,课程还涉及多线程编程、Swift与Objective-C混合编程、SwiftUI、常用第三方库等更贴合实战场景等知识点。
本专栏目标是学完可以通过Swift 独立开发过 App
致敬爱学习的你
安果移不动
精通Android,Swift,Flutter,Python,Php,按键精灵,易语言。曾为华为录制精品课程,拥有资质:按键精灵顶级证书;
产品秀:https://www.anguomob.com
B站:https://space.bilibili.com/482453235
展开
-
swift 添加友盟sdk swift 如何桥接oc Flutter接入友盟 by ios swift
终端进入工程Runner目录 执行 pod setup编辑PodFile文件 新增#必须集成 //由原来的UMCCommon变为UMCommon pod 'UMCommon' pod 'UMDevice'具体位置如下终端执行命令pod install安装好后因为我的工程是Flutter接入友盟,原生sdk已经有了新增如下配置#import <UMCommon/UMCommon.h>桥接文件也有了 没有的话可以参照...原创 2021-05-23 23:31:17 · 713 阅读 · 1 评论 -
swift tabview 带参数请求网络。多条目展示。json解析,逃逸闭包
效果:用到的第三方# Uncomment the next line to define a global platform for your project platform :ios, '9.0'target 'News' do # Comment the next line if you don't want to use dynamic frameworks use_frameworks! # Pods for News pod 'Alamofire' po原创 2020-10-08 06:35:34 · 1947 阅读 · 4 评论 -
xcode项目支持http设置
在对应清单文件添加Apptransport Security Settings 里面再添加 allow Arbitrary Loads 并设置为ye即可原创 2020-10-07 01:10:36 · 507 阅读 · 0 评论 -
swift tabbar 自定义+号 底部34导航栏适配
接上篇文章iphoneX底部34的高度 也适配了。。//// Deivices.swift// News//// Created by liuan on 2020/10/6.//import Foundationimport UIKitextension UIDevice { //刘海屏, 获取底部高度 public func getBottomHeight() -> CGFloat { var tabHeight原创 2020-10-06 10:03:22 · 1690 阅读 · 0 评论 -
swift5 搭建 tabBar (1) 完整教程【下期在这个基础上中间弄个+号】
效果前期需要的配置https://blog.csdn.net/mp624183768/article/details/108935803继续配置 为了让背景变成白色 弄一个全局的基类//// BaseViewController.swift// News//// Created by liuan on 2020/10/6.//import UIKitclass BaseViewController: UIViewController { ove..原创 2020-10-06 08:15:23 · 838 阅读 · 0 评论 -
xcode12 swift5 根视图 黑屏 新建rootViewController黑屏 代码设置主页
新建工程默认启动页面是故事版所以第一个改动的地方是这里改为空然后单机回车。第二步。改的是主要配置文件AppDelegateimport UIKit@UIApplicationMainclass AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? internal func application(_ application: UIApplication, did.原创 2020-10-06 07:43:40 · 1483 阅读 · 4 评论 -
swift5.1下拉列表
参考:LYDropListView感兴趣的老表可以从git上搜下看下这个项目 不过他的是swift3.0 ,最新的xcode已经不支持了。。所以我修改兼容了下。。进入正文效果用的核心三个类 可以把这个目录copy到工程直接使用新建Group LyDropList新建//// TDCommon.swift// Tudou//// Created by discover on 2017/8/9.// Copyright © 2017年 李雨. Al..原创 2020-10-05 03:35:21 · 1354 阅读 · 0 评论 -
The compiler is unable to type-check this expression in reasonable time; try breaking up the express
看起来没有错。 UIView.animate(withDuration: 0.2, animations: { tableView.frame = CGRect.init(x: 0, y: 40, width: screenWidth, height: (CGFloat(arr.count)*40.0 + 20.0) > screenHeight - kNaviHeight - 40 ?screenHeight - .原创 2020-10-04 22:28:28 · 5996 阅读 · 0 评论 -
swift 进入应用更新视图 NotificationCenter 传递数据更新视图
AooDelegate.swiftimport UIKitimport Alamofireimport SwiftyJSON func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { ini原创 2020-09-23 15:16:14 · 547 阅读 · 0 评论 -
keychain 生成uuid 使用获取不到数据
git官网:https://github.com/evgenyneu/keychain-swift问题 :一直获取不到数据之前代码 let keychain = KeychainSwift() keychain.accessGroup = "xxx.xxxxxxx" var cuserId: String! if let userID = keychain.get("cuserId") { ..原创 2020-09-22 11:24:28 · 738 阅读 · 0 评论 -
swift 详情页面,和自定义tab按钮
//// DetailViewController.swift// geekTime//// Created by liuan on 2020/9/16.// Copyright © 2020 liuan. All rights reserved.//import UIKitimport SnapKitimport Kingfisherclass DetailViewController: BaseViewController { var product:...原创 2020-09-16 19:21:30 · 475 阅读 · 0 评论 -
swift 公共列表的再次使用
之前定义过公共列表只需要重新定义cell//// DealListCell.swift// geekTimeSwiftUI//// Created by Ben Lv on 2020/2/8.// Copyright © 2020 ruibo. All rights reserved.//import Foundationimport UIKitimport SnapKitclass DealListCell: CommonListCell<Deal>..原创 2020-09-16 19:12:43 · 257 阅读 · 0 评论 -
swift 设置条目抽取
//// CommonCell.swift// geekTime//// Created by zhj on 2019/11/23.// Copyright © 2019 geekbang. All rights reserved.//import Foundationimport UIKitimport SnapKitclass CommonCell: UIControl { var title: String? { didSet {...原创 2020-09-16 19:03:53 · 259 阅读 · 0 评论 -
swift 泛型列表 公共列表
一般我们很多地方用到列表。那么为了优雅就可以单独抽出来//// CommonList.swift// geekTimeSwiftUI//// Created by Ben Lv on 2020/2/8.// Copyright © 2020 ruibo. All rights reserved.//import Foundationimport UIKitclass CommonListCell<ItemType>: UITableViewCell原创 2020-09-16 19:01:52 · 266 阅读 · 0 评论 -
swift 列表
效果构造//// Product.swift// geekTime//// Created by liuan on 2020/9/14.// Copyright © 2020 liuan. All rights reserved.//import Foundationstruct Product { var name:String var price: Int var imageUrl:String var desc:String原创 2020-09-15 17:40:59 · 531 阅读 · 0 评论 -
swift 轮播图
新建BannerView.swift//// BannerView.swift// geekTime//// Created by liuan on 2020/9/15.// Copyright © 2020 liuan. All rights reserved.//import Foundationimport UIKitimport SnapKitprotocol BannerViewDataSource: AnyObject { func numbe..原创 2020-09-15 16:05:53 · 1423 阅读 · 0 评论 -
swift UITabBar 实现底部tabbar,图片原色输出。
效果展示问题1 。这图怎么这么奇怪。因为图片是随便找的图看网上说合适的图片设置:1x :30X302x :60X603x :90X90也有讲48 x 32 是最合适的。。没有ui妹子只能弄个demo图片。。;了问题2 轮播图。不错。。。 下片博客贴轮播图代码正式开始首先创建两个空的ViewControllerHomeViewController//// HomeViewController.swift// geekTime...原创 2020-09-15 16:02:27 · 533 阅读 · 0 评论 -
UICollectionView must be initialized with a non-nil layout parameter【已经解决】
原因 collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: frame.width, height: frame.height))UICollectionView 中没有使用如双参数的初始化方法解法 collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: frame.width, height: frame.height),co原创 2020-09-15 15:47:41 · 2247 阅读 · 0 评论 -
swift Rswift 替换文件 无妄之灾 Build Phases->Copy Bundle Resrces Phase
请大家一定要看完再操作!!!!!替换资源文件后 我发现之前的文件copy方式没有 选择 copy if needed 这个是要选的。然后看了一篇某文章。。误删删除这个文件就好了删除这个条目是好了。然后引出来另外一个bug你怎么不讲??删除了这个文件。整个资源目录的东西。包括故事版。包括文件你都找不到了。Rswift脚本也找不到。。我还以为人家脚本出问题了这就是这样。你的问题都没解决,你tm发了一个半个的博客 过来坑人?恢复最后再通过 Build Phases-..原创 2020-09-15 11:34:47 · 321 阅读 · 0 评论 -
siwft 开发快捷操作 扩展颜色操作类,16进制数字直接转换成对应的RGB。直接操作颜色,UIbutton点击不变化颜色
//// UiColorExtension.swift// geekTime//// Created by liuan on 2020/9/14.// Copyright © 2020 liuan. All rights reserved.//import Foundationimport UIKitextension UIColor{ static func hexColor(_ hexValue:Int,alpahValue:Float)->UIColor{.原创 2020-09-14 15:56:39 · 259 阅读 · 0 评论 -
swift cartfile 依赖中 == >= ~=
== 1.0表示使用1.0版本>= 1.0 表示使用1.0或者更高的版本~>1.0 表示使用版本1.0 但是低于2.0的版本 如1.2 1.9原创 2020-09-13 19:40:17 · 288 阅读 · 0 评论 -
swift monkeyking 社交分享
https://github.com/NIXZHU/MONKEYKING官网地址如上。具体请参考官网的demo。因为我不准备用这个。。准备用友盟或者sharesdk。。因为他们有后天这个没有后台信息原创 2020-09-13 14:41:32 · 513 阅读 · 0 评论 -
swift R.swift 优雅加载资源
git官网地址:https://github.com/mac-cain13/R.swift提供一种强类型。可以自动补齐。添加依赖 pod 'R.swift'pod install 后在当前项目的targets中选择Build phrase。点击+号选择添加 New Run Script Phase.将Run Script 移动至Compile sources 之上,Check Oids Manifest.lock之下在Run Script中添加"$PODS_ROOT/R.s原创 2020-09-13 14:32:21 · 1122 阅读 · 0 评论 -
swift kingfisher 加载图片
地址:https://github.com/onevcat/Kingfisherplatform :ios, '9.0'use_frameworks!target 'videowallpaper' do pod 'Kingfisher' pod 'Alamofire' pod 'SwiftyJSON' pod 'Dollar' pod 'SnapKit' pod 'Kingfisher'end最简单的用法,直接加载图片//// ViewControll原创 2020-09-13 13:26:25 · 1562 阅读 · 0 评论 -
swift 自动布局 SnapKit
pod 'SnapKit'然后 导入//// ViewController.swift// videowallpaper//// Created by liuan on 2020/6/11.// Copyright © 2020 liuan. All rights reserved.//import UIKitimport SnapKitclass ViewController: UIViewController { override func vi原创 2020-09-11 23:20:31 · 442 阅读 · 0 评论 -
swift 开发神兵利器,Dollar
官网地址:https://github.com/ankurp/DollarDollar 是一个第三方扩展。包括了。Array,Dictionary,Object,Function,Chaining导入Dollar 直接使用即可数组扩展操作func dollarArrayTest(){ //取对应数组 组成新的数组 print(Dollar.at(["ant","bat","cat","dog","egg"], indexes: [0,2,4])) //分.原创 2020-09-11 23:06:14 · 680 阅读 · 1 评论 -
swift swiftJson 解析json
导入platform :ios, '9.0'use_frameworks!target 'videowallpaper' do pod 'Kingfisher' pod 'Alamofire' pod 'SwiftyJSON'end使用//// ViewController.swift// videowallpaper//// Created by liuan on 2020/6/11.// Copyright © 2020 liuan. All r原创 2020-09-11 22:20:48 · 1127 阅读 · 0 评论 -
swift 中内存的安全性 inout 参数访问冲突与
inout用来指针传递指针传递把参数本身引用(内存地址)传递过去,在调用的过程会影响原始数据。在Swift众多数据类型中,只有class是指针传递,其余的如Int,Float,Bool,Character,Array,Set,enum,struct全都是值传递.让值传递以指针方式传递有时候我们需要通过一个函数改变函数外面变量的值(将一个值类型参数以引用方式传递)var stepSize=1func increment(_ number: inout Int){ number +原创 2020-09-09 17:22:01 · 313 阅读 · 0 评论 -
swift some 不透明类型 不规则图形
直接上案列打印一个不规则正方形 要求返回值三角形加+(四方形+(倒三角形))返回值类型->JoindShape<Triangle,JoindShape<Square,FlippedShape<Triangle>>>看着费劲。。不友好//// AboutError.swift// learn_swiftUi//// Created by liuan on 2020/9/4.// Copyright © 2020 liuan. .原创 2020-09-07 17:50:53 · 366 阅读 · 0 评论 -
swift 错误处理do catch try try! defer
在swift中 如果我们要定义一个表示错误类型非常简单,只要遵循Error协议就可以了,我们通常用枚举或者结构体来表示错误类型,枚举可能用的多些,因为他能更直观的表达当前错误类型的每种错误细节。//// AboutError.swift// learn_swiftUi//// Created by liuan on 2020/9/4.// Copyright © 2020 liuan. All rights reserved.//import Foundationenum V原创 2020-09-04 18:44:43 · 1951 阅读 · 0 评论 -
swift 其他多线程模式
promisePipeLineMaster-SlaveSerial Thread Confinement重点看下promisePromise 缺点在需要多个操作的时候,会导致多个函数嵌套,导致代码不够直观,就是常树的Callback hell如果几个异步操作之前并没有前后顺序之分(例如不需要前一个请求的结果作为后一个请求的参数)时,同样需要等待上一个操作完成再实行下一个操作。丧尸了return 特性。什么是Promise所谓Promise...原创 2020-09-04 14:22:18 · 234 阅读 · 0 评论 -
swift 实现一个高效线程安全的Array
先来一个不安全的版本//: FROM https://www.anuomob.comimport UIKitimport PlaygroundSupport//不希望主线程执行完毕就结束PlaygroundPage.current.needsIndefiniteExecution = truevar array = Array(0...10000)func getLastItem()->Int?{ var temp:Int? = nil if array.cou原创 2020-09-02 17:46:03 · 963 阅读 · 0 评论 -
swift 如何保证线程安全和同步
首先我们先搞清楚线程为什么是不安全和不同步的死锁死锁是指两个或两个以上的进程,在执行过程中,由于竞争资源或者由于彼此通信而造成的一种阻塞的现象,若无外力作用,他们都将无法推进下去,此时称系统处于死锁状态或差生了死锁临界区这是一段代码不能被并发执行,也就是,两个线程不能同时执行这段代码竞态条件两个或多个线程读写某些共享数据,而最后的结果取决于线程运行的精确时序。比如同时操作一个余额优先级反转低优先级获得了资源。高优先级尝试获得锁 高线程的就会被挂起 中优先级就释..原创 2020-09-02 15:14:15 · 1487 阅读 · 0 评论 -
swift 多线程GCD 高级方法 DispatchGroup
DispatchGroupenter和leave 是要成对出现的//: FROM https://www.anuomob.comimport UIKitimport PlaygroundSupport//不希望主线程执行完毕就结束PlaygroundPage.current.needsIndefiniteExecution = truelet workingGroup = DispatchGroup()let workingQueue = DispatchQueue(label原创 2020-08-31 18:08:07 · 1555 阅读 · 1 评论 -
swift GCD 基本操作
sync async asyncAfterGCD-串行 vs 并行GCD-同步 vs 异步GCD- sync提交任务到当前队列里,并且直到任务完成,当前队列才会返回GCD-async调度一个任务区立即执行但是不用等任务完成就会直接返回code//: FROM https://www.anuomob.comimport UIKitimport PlaygroundSupport//不希望主线程执行完毕就结束PlaygroundPage.curre原创 2020-08-31 15:15:14 · 254 阅读 · 0 评论 -
swift 多线程 GCD概念
任务+队列 易用 效率 性能底层是开源的底层地址:https://opensource.apple.com/tarballs/libdispatch/主要功能创建管理Queue 提交job Dispatch Group 管理Dispatch Object 信号量Semaphore 队列屏障 Barrier Dispatch Source Queue Context数据 DispatchI/O Channel Disaptch Data 对象重要概念-队列主..原创 2020-08-31 14:59:01 · 249 阅读 · 0 评论 -
swift 多线程,CocoaOperation,Operation + OperationQueue
两个都是面向对象的取消,依赖,优先级处理,复杂逻辑,保存业务状态,子类化Operation分为两类Operation相当于父类BlockOperation继承父类 可以用传递闭包进行操作Opreation分别有四种状态isReady isExecuting isFinished isCancelled运行状态有两种sync 同步需要实现main()方法async 异步 (网络操作)start() 开启线程方法isAsynchronous 是否异...原创 2020-08-31 14:41:49 · 486 阅读 · 0 评论 -
Swift 多线程、为什么几乎所有的gui 都是单【主】线程的
https://community.oracle.com/blogs/kgh/2004/10/19/multithreaded-toolkits-failed-dream大概就意思就是。。如果是多线程渲染。虽然速度很快,但是问题会出现很多那么多线程可以做什么?网络请求 ,io,计算,数据模型转换等等如图,上面是理想多线程与下面是现实多线程多线程Thread 最原始,裸露Cocoa Operation(Operation 和OperationQueue) 封装最好Gr.原创 2020-08-31 00:20:48 · 413 阅读 · 0 评论 -
swift泛型下标
//: FROM https://www.anuomob.comimport UIKitprotocol Container{ associatedtype Item mutating func append(_ item:Item) var count:Int{get} subscript(i:Int)->Item {get} }extension Container{ subscript<Indices:Sequen.原创 2020-08-30 23:38:00 · 193 阅读 · 0 评论 -
swift 泛型中的where 比较两个数组是否相等
//: FROM https://www.anuomob.comimport UIKitprotocol Container{ associatedtype Item mutating func append(_ item:Item) var count:Int{get} subscript(i:Int)->Item {get} associatedtype Iterator:IteratorProtocol where Iterator.E.原创 2020-08-30 23:20:00 · 1088 阅读 · 0 评论