GithubHelp home page GithubHelp logo

Comments (3)

yangyangnote avatar yangyangnote commented on July 17, 2024 1

估计得跟上面连着一块看,而且要把leftjustify中的left去掉

var alignment = TextAlignment.justify

switch alignment {
case .left:
    print("left aligned")

case .right:
    print("right aligned")

case .center:
default:
    print("center aligned")
}

表示虽然枚举中添加了成员值,虽然把情况全覆盖,但是输出的不是我们想要的值

from turingwechatgroups.

yangyangnote avatar yangyangnote commented on July 17, 2024

应该跟这句话有关系
如果在枚举中增加了一个成员值但是没有更新switch语句,那么switch语句在遇到新的成员值时会跳到default。代码能编译通过,但不是你想要的结果,正如我们在代码清单14-8中看到的那样。

from turingwechatgroups.

Story5 avatar Story5 commented on July 17, 2024

@yangyangnote 确实是的,是书中的错误,多了个left.你可以去图灵《Swift编程权威指南(第2版)》页面提交勘误.

这段代码要表达的意思就是不建议用default分支去判断枚举,而建议使用case列举全部成员变量,这样有助于后期在增减枚举类型成员变量时,更好的维护,不容易出错.

from turingwechatgroups.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.