iOS基础
文章平均质量分 60
依旧风轻
葵花成海,你在不在
展开
-
在主线程和非主线程调用 DispatchQueue.main.sync { }
在 Swift 中,`DispatchQueue.main.sync { }` 的行为取决于当前执行代码的线程。原创 2024-07-04 01:23:48 · 369 阅读 · 0 评论 -
异步派发和同步派发的区别
核心区别是: 是否会阻塞当前线程中正在执行的任务。原创 2024-06-11 17:49:51 · 421 阅读 · 0 评论 -
执行异步派发时, 需要拷贝块
拷贝行为会拷贝 block,以确保 block 在异步执行时有效。安全性: 这样做是为了确保 block 中引用的变量在函数返回后依然有效,防止引用无效的局部变量。这个行为是 GCD (Grand Central Dispatch) 的设计之一,旨在确保异步任务的安全性和稳定性。原创 2024-06-11 15:25:49 · 511 阅读 · 0 评论 -
理解GCD中的并发队列
Concurrent queues (also known as a type of global dispatch queue) execute one or more tasks concurrently, but tasks are still started in the order in which they were added to the queue. The currently executing tasks run on distinct ([dɪˈstɪŋkt] adj. 不同的) t原创 2024-06-11 14:41:40 · 139 阅读 · 0 评论 -
理解dispatch_async
提交一个块以在调度队列上异步执行并。原创 2024-06-11 13:53:09 · 522 阅读 · 0 评论 -
weak的底层原理
弱引用表的键是被引用对象的内存地址,而值是一个集合,包含了所有指向该对象的弱引用指针的地址。当对象被释放时,运行时会在弱引用表中找到所有指向该对象的弱引用,并将它们置为nil,然后删除对应的条目。通过这种机制,iOS 保证了weak引用的安全性和可靠性。原创 2024-06-05 07:59:02 · 737 阅读 · 0 评论 -
小心串行队列的执行依赖
iOS串行队列中任务的执行先后原创 2024-03-18 04:13:38 · 178 阅读 · 0 评论 -
日期相关需求速查备忘录 (Swift版本)
默认环境// The user’s current calendar. 日历默认为系统当前let cal = Calendar.current// 日历的 locale 为 nil 或者 Locale.currentcal.locale == nil// 日历的 timeZone 为 TimeZone.current (The time zone currently used by the system)cal.timeZone == TimeZone.currentDemand List原创 2023-03-29 22:45:16 · 70 阅读 · 0 评论 -
怎样手动计算多行字符串的高度?
How to calculate multi-lines String’s height ?使用的具体方法extension NSString { @available(iOS 7.0, *) open func draw(with rect: CGRect, options: NSStringDrawingOptions = [], attributes: [NSAttributedString.Key : Any]? = nil, context: NSStringDrawingCo原创 2022-04-20 14:44:01 · 1448 阅读 · 0 评论 -
初识`valueForKeyPath:`
初识valueForKeyPath:官方文档:// 返回由给定键路径标识的派生属性的值。Returns the value for the derived property identified by a given key path.完整声明:- (id)valueForKeyPath:(NSString *)keyPath;参数说明// keyPath参数// ...原创 2019-02-02 16:35:29 · 226 阅读 · 0 评论 -
UIView类的回调方法
当视图的层级发生变动时, 系统会调用相关视图中的特定的方法. iOS SDK 提供了6个回调方法. 可以此来追踪视图的变动.1. didAddSubview: 方法2. willRemoveSubview: 方法3. willMoveToSuperview: 方法4. didMoveToSuperview方法5. willMoveToWindow: 方法6. didMoveToWindow 方法原创 2017-06-29 22:07:08 · 1307 阅读 · 2 评论 -
UIImageView的约束问题
[情况一]先创建UIImageView对象,再设置其image属性/* * 在控制器的-viewDidLoad方法中调用如下方法 * 布局使用Masonry框架 * 项目中有两张图片①sqi_test.png②sqi_test.jpg,都为400×400像素 */#pragma mark - UI- (void)setupUI { UIImageView *imgView = [UI原创 2017-06-24 23:43:17 · 1778 阅读 · 0 评论 -
imageNamed和imageWithContentsOfFile
Apple官方文档文档理解+ imageNamed:方法UIImageView *imgView = [UIImageView new];imgView.image = [UIImage imageWithContentsOfFile:@"sqi_test.png"];此方法会首先在系统缓存中查找指定的Image对象,并返回最适合当前主屏幕的Image变量(the variant of that原创 2017-06-24 16:46:18 · 424 阅读 · 1 评论