·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> StanfordiOSLearnNotes-1

StanfordiOSLearnNotes-1

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23

这段时间在学习Stanford的iOS 8 的教学视频,学而不思则怠,所以准备总结一下看视频学习的一些笔记,便于自己加深理解。

吐槽一下就是现在的学习材料有好多英文的,又有好多中文的,杂乱到最后的结果就是,我自己也不知道某些英文用中文咋说,某些中文用英语咋说了……好凌乱……

现在已经学了6节课,从这六节课看,前三节课主要是讲了一个Calculator的Demo,并穿插了很少一些iOS的介绍,以及MVC的介绍。第四节主要是介绍了一些Swift的语法,第五节和第六节主要讲述了iOS的触控操作(可能就是传说中的Cocoa Touch),并且穿插了一些Swift的语法。因此,现在需要总结的内容分为三部分:

  1. 总结一下教授对iOS的简介
  2. 总结一下教授在这六节课里面讲的语法
  3. MVC,Cocoa Touch, Happiness Demo (这个在下面文章讲吧。一篇笔记贴不完)

1. iOS简介

iOS有四个层次构成:

  1. Core OS。 毕竟iOS是一个Operation system,这里提供了最基本的操作系统服务。
  2. Core Services。
  3. Media。 这是一个很重要的需要了解的层次。但是在Stanford的课程里面,教授说因为时间问题,他不会讲这些。
  4. Cocoa Touch。 这是这节课主要集中的一个层次(layer)。也是开发一个简单的App,最先接触的层次。

iOS开发的一些相关需求:

  1. Tools: Xcode,Instruments (在Xcode中 cmd+i打开)
  2. Language: 毫无疑问这个课程集中于Swift,此外还要牵涉到Obj-c,毕竟Cocoa Touch Lib还是Obj-c的。
  3. Frameworks:Foundation,Core Data,UIKit,Core Motion,Map Kit  觉得教授只是说了这个课程里面会牵涉到的一些Frameworks
  4. Design Strategy: MVC (这在六节课里面,我觉得这个是最重磅的一个知识点了)

2. Swift语法

其实Swift的语法直接看Apple的Swift Language文档就行了,但是觉得在课堂上听到的,会理解的更直接一点。毕竟教授会立即把这些点用到Demo里面。在这六节课中,穿插的语法并不是特别多,主要有Optional Chain,Enum,Extension,PRoperty。这些语法的用法总结如下。

  1. Array, Dictionary
    1. 两种定义方法。 Array<string>(), [string]()
  2. Computed properties (instance variables which are computed rather than stored) {set,get}
  3. switch
    1. switch varName { case value1 procedure1; case value2 procedure2; default procedure else;)
    2. case 中的var如果是enum,内部是可以定义变量的。这个是有enum的特性决定的。
  4. Functions as types
    1. if return is void, should declare the return value type as void still
  5. Closure syntax for defining functions “on the fly"
  6. Methods with the same name but different argument types
  7. Optional
  8. Range
    1. struct Rannge<T> {var startIndex:t var endIndex:T}
    2. An array’s range would be Range<Int>
    3. A string subrange is not Range<Int>,it’s Range<string.Index>
    4. … with ..<
  9. Enum
    1. Swfit里面的Enum很强大,可以有原始值(RawValue),这个和其他语言差不多。
    2. Swift的值可以有相关值,这是一个很强大的功能。
  10. Data Structures in Swift: Classes, Structures and Enumerations. Differences:
    1. Inheritance (class only)
    2. Introspection and casting (class only)
    3. Value type (struct, enum) vs reference type (class)
    4. For value type: you must note any fun that can mutate a struct/ enum with the keyWord mutating
  11. Method
    1. Override super clases method/var should has a keyword “override” before func/var
    2. A method can be marked final which will prevent subclass from being able to override.
    3. Classes can also be marked as final
    4. Both types and instances can have methods, declare a type method or property with a static keyword 
    5. Internal name vs External name
  12. Properties
    1. Property Observers, willset/didset
    2. One very common thing to do in an observer in a controller is to update the user-interface
    3. Lazy Initialization
  13. Initialization
    1. 对于struct,如果没有init函数,那么会默认的给你加上一个init函数。参数为内部各个变量。
    2. Constant properties can also be set in init function.
    3. init机制非常复杂,光分析这个init机制估计就够一篇文章了,这里就不详细描述了。主要有convenience init,designated init。
    4. 我觉得主要的理解思路就是designate init侧重于分配空间,初始化。convenience init侧重于计算赋值。
    5. init函数的继承机制。如果没有实现任何designated inits,那么继承所有的designated inits;如果没有override所有的designated inits,那么继承所有的convenience inits。如果没有实现任何inits,那么继承所有。
    6. Required inits
    7. Failable init
  14. AnyObject, introspection and casting (is and as)
    1. var cals = destinationViewController as CalculatorViewController. It will crash if the type is not compatible.
    2. var cals = destinationViewController as? CalculatorViewController. Return nil if the type is not compatible.
    3. if destinationViewController is CalculatorViewController, check if the type is compatible.
    4. The Array type could be casted also.
  15. Methods and Functions
  16. Type Conversion using init():
    1. let d = Int(2.3) //d=2
  17. Assertions: assert(()->Book, “message”). Asserts will be ignored for release.
  18. Objective-C compatibility:
    1. String vs NSString, Array vs NSArray, Dictionary vs NSDictionary and other Obj-C classes: NSObject, NSNumber, NSDate, NSData
  19. Property List,NSUserDefaults
    1. Property List is really just the definition of term.
    2. 从教授演示的Demo看,Property List就是一个约定俗成的变量,用来存储Class内部的信息。这个变量一般用AnyObject实现,然后通过Cast,转换成各种需要的信息。其中如果转换,是自定义实现的。
    3. 存储的原始类型必须为NSString,NSArray,NSDictionary,NSNumber,NSDate,NSData
    4. Property List的具体操作使用NSUserDefaults实现的。NSUserDefaults通过key来读取或存储Property List。具体的API这里就不总结了,以后遇到了具体总结一下这个用法吧。
  20. 接下来教授就讲了View,我觉得就是Cocoa Touch框架吧(凭现有的知识,还不能确定。再另开一篇文章写吧)。
  21. Extensions
  22. Protocols(就是interface啦,没啥新鲜的东西。主要就是,可以知道必须由Class实现,如果不制定的话,可以更改内部的方法要价格mutating,对于一个var必须指定是只读的,还是可以读写的)