{"id":15687484,"url":"https://github.com/zhongwuzw/ios-developer-interview-questions-solutions","last_synced_at":"2026-02-23T20:16:25.883Z","repository":{"id":74773294,"uuid":"60274923","full_name":"zhongwuzw/iOS-Developer-Interview-Questions-Solutions","owner":"zhongwuzw","description":"iOS 开发面试问题","archived":false,"fork":false,"pushed_at":"2018-02-28T14:53:05.000Z","size":8,"stargazers_count":9,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T11:41:51.026Z","etag":null,"topics":["interview","ios"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zhongwuzw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-02T15:21:19.000Z","updated_at":"2022-02-20T14:38:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"4c689519-de73-46d7-aaec-24efe0a7d018","html_url":"https://github.com/zhongwuzw/iOS-Developer-Interview-Questions-Solutions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhongwuzw%2FiOS-Developer-Interview-Questions-Solutions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhongwuzw%2FiOS-Developer-Interview-Questions-Solutions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhongwuzw%2FiOS-Developer-Interview-Questions-Solutions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhongwuzw%2FiOS-Developer-Interview-Questions-Solutions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhongwuzw","download_url":"https://codeload.github.com/zhongwuzw/iOS-Developer-Interview-Questions-Solutions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251362153,"owners_count":21577403,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["interview","ios"],"created_at":"2024-10-03T17:48:54.543Z","updated_at":"2026-02-23T20:16:20.832Z","avatar_url":"https://github.com/zhongwuzw.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# iOS 开发面试问题\n\n根据[iOS开发面试问题](https://github.com/lzyy/iOS-Developer-Interview-Questions) 写了部分答案。\n\n**Update: 20180228 \n突然发现几年前创建了这个`Repo`，还是更新一下吧，Sigh.**\n\n面试 iOS 开发时，切入点很重要，不同的切入点会导致不同的结果，没有找到合适的切入点也无法对应聘者有一个全面的了解。所以这份面试问题列表更多的是提供方向，没有固定的答案，而且可以根据应聘者的回应引出更多有意思深层次的讨论。\n\n如果有不错的问题，欢迎 Pull Request :)\n\n## 一般性问题\n* 最近这两天你有学到什么知识/技能么？\n* 最近有做过比较酷或者比较有挑战的项目么？\n* 最近看过的书/文章有哪些？\n* 如何向一个只接触过互联网的孩子解释「电视」？\n* 为什么要学习编程，编程对你而言的乐趣在哪儿？\n* 如果一个函数10次中有7次正确，3次错误，问题可能出现在哪里？\n* 自身最大优点是什么，怎么证明？\n* 有没有在 GitHub 上发布过开源代码，参与过开源项目？\n* 你最近遇到过的一个技术挑战是什么？怎么解决的？\n* 开发常用的工具有哪些？\n* 熟悉 CocoaPods 么？能大概讲一下工作原理么？\n* 最常用的版本控制工具是什么，能大概讲讲原理么？\n* 今年你最想掌握的一门技术是什么？为什么？目前已经做到了哪个程度？\n* 你一般是怎么用 Instruments 的？\n* 你一般是如何调试 Bug 的？\n* 你在你的项目中用到了哪些设计模式？\n* 如何实现单例，单例会有什么弊端？\n* iOS 是如何管理内存的？\n\n## 知识性问题\n* 什么是响应链，它是怎么工作的？ \n\n **具体可参考**[iOS事件处理之Hit-Testing](https://zhongwuzw.github.io/2016/09/12/iOS%E4%BA%8B%E4%BB%B6%E5%A4%84%E7%90%86%E4%B9%8BHit-Testing/)\n\n* 如何访问并修改一个类的私有属性？ \n\n 1. **通过KVC,`setValue:forKeyPath:`方法。**\n 2. **对于property，可以使用`- (id)performSelector:(SEL)aSelector withObject:(id)anObject`，不过注意，属性值只能是`id`，也就是`Objective-C`类型**。\n 3. **使用`NSInvocation`来进行设置**。\n 4. **通过`objc_msgSend`发送`setProperty`来进行设置**。\n 5. **通过`class_getInstanceMethod`拿到`Method`，再调用`method_invoke(id receiver, Method m, ...)`来调用`setter`**。\n 6. **其它运行时方法不再赘述**。\n \n* iOS Extension 是什么？能列举几个常用的 Extension 么？\n \n **通过使用扩展，可以让我们在应用外实现一些自定义的功能，这样，我们可以在其它的`App`或系统中进行交互。我们经常用的比如输入法，照片编辑、分享等等。**\n \n* 如何把一个包含自定义对象的数组序列化到磁盘？\n\n **对象实现NSCoding协议，其父类同样需要实现。**\n \n* Apple Pay 是什么？它的大概工作流程是怎样的？\n\n **不赘述，参见**[Apple Pay实现原理](https://www.zhihu.com/question/40502548)\n\n* iOS 的沙盒目录结构是怎样的？ App Bundle 里面都有什么？ \n\n **包括`Documents`、`Library`、`tmp`等。`Application Bundle`包括`Info.plist`，可执行文件，资源文件及其它文件，比如`frameworks`**。\n\n* iOS 的签名机制大概是怎样的？\n* iOS 7的多任务添加了哪两个新的 API? 各自的使用场景是什么？\u003cp\u003e**定时fetch内容以及push唤醒并下载内容。**\n* Objective-C 的 `class` 是如何实现的？`Selector` 是如何被转化为 C 语言的函数调用的？\n\n **几句话很难讲清楚，直接上源码吧，我创建的项目，加了中文注释。**[objc4-cn](https://github.com/zhongwuzw/objc4-cn)\n\n* `UIScrollView` 大概是如何实现的，它是如何捕捉、响应手势的？\n \n **改变一个视图的bounds.origin后，它每一个单独的子视图都会被移动，这就是UIScrollView工作的原理，当你设置它的contentOffset属性时它改变scroll view.bounds的origin。手势应该是使用手势识别器实现的。**\n \n* Objective-C 如何对已有的方法，添加自己的功能代码以实现类似记录日志这样的功能？\n \n **利用OC的运行时特性，运用swizzling Method方法即可实现。**\n \n* `+load` 和 `+initialize` 的区别是什么？\n\n **时机不一样；当涉及到继承、类别等时，调用的情况也不一样**。参见[源码](https://github.com/zhongwuzw/objc4-cn)\n \n* 如何让 Category 支持属性？\n\n **使用关联引用。**\n \n* `NSOperation` 相比于 GCD 有哪些优势？\n\n **NSOperation加入到queue的操作可以取消，NSOperation优先级设置、依赖等比较方便。**\n \n* `strong` / `weak` / `unsafe_unretained` 的区别？\n\n **weak会在对象引用计数变为0时置为nil，而unsafe_unretained不会，所以当指向对象释放后，再访问时可能导致崩溃。**\n \n* 如何为 Class 定义一个对外只读对内可读写的属性?\n\n **在头文件中定义属性，关键字为readonly，在实现文件中定义扩展，在扩展中重新定义属性即可，默认可读写。**\n \n* Objective-C 中，meta-class 指的是什么？\n\n **元类中包含类方法，isa及superclass指针。参考[objc4-cn](https://github.com/zhongwuzw/objc4-cn)**\n \n* `UIView` 和 `CALayer` 之间的关系？\n\n **UIView依靠CALayer来做渲染管理。**\n \n* `+[UIView animateWithDuration:animations:completion:]` 内部大概是如何实现的？\n **封装了CABasic动画。**\n \n* 什么时候会发生「隐式动画」？\n\n **改变视图非基础图层的CALayer时。**\n \n* 如何处理异步的网络请求？\n* `frame` 和 `bounds` 的区别是什么？\n\n **frame相对于父视图坐标系，bounds是自己的坐标系，供子视图参考。**\n \n* 如何把一张大图缩小为1/4大小的缩略图？\n\n **使用GraphicContext**\n \n* 一个 App 会处于哪些状态？\n\n ![](https://raw.githubusercontent.com/zhongwuzw/zhongwuzw.github.io.resource/master/images/app-state.png)\n\n* Push Notification 是如何工作的？\n* 什么是 Runloop？\n\n 具体实现可以参考[源码]([objc4-cn](https://github.com/zhongwuzw/objc4-cn))，简单可以理解成，`RunLoop`就是一个`while(1){}`的循环，每次进行循环时，获取需要处理的事件分发，当没有任何事件需要处理时则休眠。\n\n* Toll-Free Bridging 是什么？什么情况下会使用？\n\n **C和OC之间的转换，涉及到对象所有权的管理。**\n \n* 当系统出现内存警告时会发生什么？\n\n **除了调用方法让用户处理外，系统默认移除当前不可见的controller的view。**\n \n* 什么是 `Protocol`，Delegate 一般是怎么用的？\n* autorelease 对象在什么情况下会被释放？\n\n `autorelease`对象内存由`NSAutoreleasePool`进行管理，当程序离开其范围时，向管理的`autorelease`对象发送`release`进行。\n\n* UIWebView 有哪些性能问题？有没有可替代的方案。\n\n **UIWebView存在内存泄露，`JavaScript`渲染引擎受限，在主线程进行大量操作；使用私有`API`开启`WebThread`线程渲染，如`_setDrawInWebThread`/`_setDrawsCheckeredPattern`等；使用WKWebView替换。**\n \n* 为什么 NotificationCenter 要 removeObserver? 如何实现自动 remove?\n\n **如果不remove，当observer释放后，NotificationCenter会继续向其发送通知，此时会导致崩溃。实现自动remove方法：使用一个对象作为其关联对象，当对象释放时会调用关联对象的dealloc方法，在该方法中移除即可。注意，如果`App`的`target`是`iOS9.0`及以后，则不再需要进行`removeObserver`操作**\n \n \n* 当 `TableView` 的 `Cell` 改变时，如何让这些改变以动画的形式呈现？\n* 什么是 `Method Swizzle`，什么情况下会使用？\n\n## 经验类问题\n* 为什么 `UIScrollView` 的滚动会导致 `NSTimer` 失效？\n\n **NSTimer涉及到RunLoop Mode，当滑动时，模式处于UITrackingRunLoopMode，导致原模式下的Timer失效。**\n \n* 为什么当 Core Animation 完成时，layer 又会恢复到原先的状态？\n **动画的过程涉及到绘图原理，动画是在presentationLayer上实现，而Layer原来的状态都是保存在modelLayer，改变presentationLayer属性并不会改变modelLayer的值。**\n \n* 你会如何存储用户的一些敏感信息，如登录的 token。\n\n **使用keychain。**\n \n* 有用过一些开源组件吧，能简单说几个么，大概说说它们的使用场景实现。\n* 什么时候会发生 `EXC BAD ACCESS` 异常？\n\n **访问僵尸对象。**\n \n* 什么时候会使用 Core Graphics，有什么注意事项么？\n* NSNotification 和 KVO 的使用场景？\n* 使用 Block 时需要注意哪些问题？\n\n **循环引用吧。**\n \n* `performSelector:withObject:afterDelay:` 内部大概是怎么实现的，有什么注意事项么？\n* 如何播放 GIF 图片，有什么优化方案么？\n* 使用 `NSUserDefaults` 时，如何处理布尔的默认值？(比如返回 NO，不知道是真的 NO 还是没有设置过)\n\n **先使用objectForKey判断是否为nil。**\n \n* 有哪几种方式可以对图片进行缩放，使用 CoreGraphics 缩放时有什么注意事项？\n* 哪些途径可以让 ViewController 瘦下来？\n* 有哪些常见的 Crash 场景？\n\n **对象无法响应selector；未移除observer；访问已释放对象；数组越界**\n \n\n## 综合类问题\n* 设计一个可以无限滚动并且支持自动滚动的 SlideShow。\n* 设计一个进度条。\n* 设计一套大文件（如上百M的视频）下载方案。\n\n 切片分段多线程并发下载。\n\n* 如果让你来实现 `dispatch_once`，你会怎么做？\n\n 使用原子变量，做好内存序使所有线程可见。\n \n* 设计一个类似 iOS 主屏可以下拉出现 Spotlight 的系统。(对 UIScrollView 的理解程度)\n\n## 编程实现\n* 简述[「Snakes and Ladders」](http://en.wikipedia.org/wiki/Snakes_and_Ladders)的实现思路(这道题比较容易阐述清楚，且难度适中)\n\n## 参考\n\n* http://way2ios.com/development/ios-development-2/iphone-interview-question-answers/\n* https://blackpixel.com/writing/2013/04/interview-questions-for-ios-and-mac-developers-1.html\n* https://github.com/CameronBanga/iOS-Developer-and-Designer-Interview-Questions\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhongwuzw%2Fios-developer-interview-questions-solutions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhongwuzw%2Fios-developer-interview-questions-solutions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhongwuzw%2Fios-developer-interview-questions-solutions/lists"}