bookmate game

Matt Neuburg

  • aspirцитує2 роки тому
    (The print command provides instant feedback in the Xcode console.)
  • aspirцитує2 роки тому
    You are free to put a semicolon at the end of a statement that is last or alone on its line, but no one ever does
  • aspirцитує2 роки тому
    You can also enclose comments in /*...*/
  • aspirцитує2 роки тому
    Swift is a compiled language. This means that your code must build — passing through the compiler and being turned from text into some lower-level form that a computer can understand — before it can run and actually do the things it says to do.
  • aspirцитує2 роки тому
    The Swift compiler is very strict; in the course of writing a program, you will often try to build and run, only to discover that you can’t even build in the first place, because the compiler will flag some error, which you will have to fix if you want the code to run.
  • aspirцитує2 роки тому
    In Swift, “everything is an object.” That’s a boast common to various modern object-oriented languages, but what does it mean? Well, that depends on what you mean by “object” — and what you mean by “everything.”
    Let’s start by stipulating that an object, roughly speaking, is something you can send a message to. A message, roughly speaking, is an imperative instruction. For example, you can give commands to a dog: “Bark!” “Sit!” In this analogy, those phrases are messages, and the dog is the object to which you are sending those messages.
    In Swift, the syntax of message-sending is dot-notation. We start with the object; then there’s a dot (a period); then there’s the message. (Some messages are also followed by parentheses, but ignore them for now; the full syntax of message-sending is one of those details we’ll be filling in later.) This is valid Swift syntax:
    fido.bark()
    rover.sit()
  • aspirцитує2 роки тому
    Just as 1 is actually an object, + is actually a message; but it’s a message with special syntax (operator syntax). In Swift, every noun is an object, and every verb is a message.
  • aspirцитує2 роки тому
    An object type can be extended in Swift, meaning that you can define your own messages on that type. For example, you can’t normally send the sayHello message to a number, but you can change a number type so that you can:
    extension Int {
    func sayHello() {
    print("Hello, I'm \(self)")
    }
    }
    1.sayHello() // outputs: "Hello, I'm 1"
fb2epub
Перетягніть файли сюди, не більш ніж 5 за один раз