• Swift 学习笔记

    看了下别人的源码,发现有一个这样的写法我不大熟悉,原来是Swift中的Access Control

      public final class Map {
      	public let mappingType: MappingType
      	
     -	var JSONDictionary: [String : AnyObject] = [:]
     +	public internal(set) var JSONDictionary: [String : AnyObject] = [:]
      	public var currentValue: AnyObject?
      	var currentKey: String?
      	var keyIsNested = false
     
    @@ -157,4 +157,4 @@ private func valueFor(keyPathComponents: ArraySlice<String>, dictionary: [AnyObj
      	}
      	
      	return nil
     -}  
     +}
    

    其中:

    public internal(set) var JSONDictionary: [String : AnyObject] = [:]
    

    书上是这样定义的:

    • Public access enables entities to be used within any source file from their defining module, and also in a source file from another module that imports the defining module. You typically use public access when specifying the public interface to a framework.
    • Internal access enables entities to be used within any source file from their defining module, but not in any source file outside of that module. You typically use internal access when defining an app’s or a framework’s internal structure.
    • Private access restricts the use of an entity to its own defining source file. Use private access to hide the implementation details of a specific piece of functionality.

    Getters and Setters

    Getters and setters for constants, variables, properties, and subscripts automatically receive the same access level as the constant, variable, property, or subscript they belong to.

    You can give a setter a lower access level than its corresponding getter, to restrict the read-write scope of that variable, property, or subscript. You assign a lower access level by writing private(set) or internal(set) before the var or subscript introducer.

    大概的意思就是如果要公开Getter方法给别人,可以这样定义API

    public internal(set) var someproperty
    

    通过internal(set)把Setter的访问权限设置成internal级别,就可以保护Setter 不被公开出去。




  • Hello World to Jekyll!

    折腾了一天终于能试着发表一篇Blog了。我用的是jekyll,搭建在Github Page上,基本上跟以前用WordPress的独立Blog差不多。最近正好学习Bootstrap以及一些前端的基础知识,感觉这种轻量级别的网页框架还挺好掌握的,当然发表一篇Blog的感觉,也正如jekyll宣传的像黑客一样。=。=!

    2016年的农历新年已经过完,现在都3月1号,新的开始。今年的目标

    • 做完一个收费的App
    • 撸完一个网站
    • 获得FreeCodeCamp的全栈工程师证书