博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS面试准备
阅读量:5824 次
发布时间:2019-06-18

本文共 3353 字,大约阅读时间需要 11 分钟。

1. List and explain: iOS Application States

Not running: has not been lanuched or terminated by the system

Inactive: Running in foreground and not receiving events Stay briefly on their way to be active.

Active:Running in foreground and receiving events.

Background: Running in background and executing code. Stay briefly on their way to be suspended.

Suspended: Remains in memory but does execute any code.

2. iOS Compiler optimizes references to string objects that have the same value

NSString *firstName = @"Jack";NSString *secondName = @"Jack";if (firstName == secondName) {    NSLog(@"areEqual");} else {    NSLog(@"areNotEqual");}

firstName and secondName are pointers to different objects that have the same value. But the optimization machanism of iOS compiler let both pointers actually pointing to same address.

In Swift, Closures and functions are also assigned by reference. If variable or constant A and B are assigned to the same closure or function, they gonna have exactly the same value in memory.

3. Concurrency

==Thread: Not suggested, hard to design

==Dispatch queues: First in First out only. GCD takes care of creating the needed threads and scheduling tasks to run on those threads.

==Operation Queue: Implemented by NSOperationQueue not limited to FIFO order and support complex execution order graphs for your tasks.

 

4.Swift Retain Cycle

1 class A { 2  3   let b:B 4  5   init() { 6  7     b = B() 8  9     b.a = self10 11   }12 13   deinit () {14 15     print("A deinit")16 17   }18 19 }20 21 class B {22 23   var a:A? = nil24 25   deinit {26 27     print(B deinit")28 29   }30 31 }

 To resolve a retain cycle

When property A and B must not be nil, one should be assigned unowned reference and the other one should be implicitly unwrapped optional

When one of property A or B could be nil, the one which can't be nil should be assigned unowned.

When both of the property A and B could be nil, assign weak for one property.

 

5. Objective-C 单例写法 Singleton 

@implementation MyManager+ (id)sharedManager {  static MyManager * staticInstance = nil;  static dispatch_once_t onceToken;  dispatch_once(&onceToken, ^{    staticInstance = [[self alloc] init];  });   return staticInstance;}@end

 6.  Available prefixs to keyword func in Swift

override: to override methods in superclass you must write override before func

class: to implement a class method you must write class before func

static: to implement a structures/enumerations method you must write static before func

mutating: for all structures/enumerations methods that could change the instance properties, you must write mutating before func

7. Closures Classification

Global Function: do not capture values

Nested Function: capture values from enclosing function

Closure Expression: A unamed closure that capture values from surrounding context

{(parameters) -> (return type) in    statements}

 8. Closure Shorthand

reversed = names.sort( { (s1:  a href="" String /a , s2:  a href="" String /a ) ->  a href="" Bool /a  in return s1 > s2 } )

Inferring Type from context

reversed = names.sort( { s1, s2 in return s1 > s2 } )

Implicit Returns from Single-Expression Closures

reversed = names.sort( { s1, s2 in s1 > s2 } )

Shorthand Argument Names

reversed = names.sort( { $0 > $1 } )  

Operator Functions

reversed = names.sort(>)

 

 

转载于:https://www.cnblogs.com/leyun/p/5309517.html

你可能感兴趣的文章
30个非常时尚的网页联系表单设计优秀示例
查看>>
使用membership(System.Web.Security)来进行角色与权限管理
查看>>
opticom 语音质量验证白皮书
查看>>
3D实时渲染中的BSP树和多边形剔除
查看>>
Frank Klemm's Dither and Noise Shaping Page: Dither and Noise Shaping In MPC/MP+
查看>>
网络抓包的部署和工具Wireshark【图书节选】
查看>>
Redis在Windows+linux平台下的安装配置
查看>>
Maven入门实战笔记-11节[6]
查看>>
Local declaration of 'content' hides instance variable
查看>>
ASP.NET中 HTML标签总结及使用
查看>>
Linux下日志系统的设计
查看>>
爬虫IP被禁的简单解决方法——切换UserAgent
查看>>
php生成word,并下载
查看>>
紫书 习题8-11 UVa 1615 (区间选点问题)
查看>>
asp.net mvc学习(Vs技巧与Httpcontext)
查看>>
float数据在内存中是怎么存储的
查看>>
开发经验和习惯
查看>>
dedecms 修改标题长度可以修改数据库
查看>>
Matplotlib学习---用matplotlib画直方图/密度图(histogram, density plot)
查看>>
MySQL案列之主从复制出错问题以及pt-slave-restart工具的使用
查看>>