1. Swift is used to determine whether option is nil, which is equivalent to If (option) of OC) If let name = option {greeting = "If ===="} else {greeting = "else = "} 2. After running the matching clause in the switch, the program exits the switch
When learning new things, I often encounter some problems that I cannot solve at the time. I want to record them and understand them in depth, but I will always forget them. So, right! This article is a pitfall! Leave it blank!
Problem description:
The first step is to set up the environment. I am an Apple system, and I am a poor boy. 8 K computers are far away from me. I am a black apple by myself. The total price is 1 K. I just need to learn enough. During this period, I learned a lot. That
1. Send a notification. (Take this notification as an example. The notification name is gameovernotification. Notification parameter: title) Nsicationicationcenter. defacenter Center (). postnotificationname ("gameovernotification", object: title)
1. Define an agreement first. Protocol httptoolprorocol {// 1. The proxy method that passes the dictionary returned by the server to the caller func didrecieveresults (Result: nsdictionary )} 2. Define a proxy Property // 2. Declare the
When reading the dev guide, there are some constraints about the request parameters, but the distribution is scattered. I sorted it out this morning and did some verification. Now I am releasing the Po.
1) account, object, and container custom
1. Assertions
Let age =-3 assert (age> = 0, "a person's age cannot be less than zero") // The assertion is triggered because age
2. The SWIFT value assignment operator (=) does not return values, so as to prevent errors caused by writing the
Extends new functions based on existing classes and struct types. Syntax:
extension SomeType{// new functionality to add to SomeType goes here}An extension can extend an existing type to make itadopt one or more protocols.Where this is the case,the
Fengsh998 original address: Sorry!
Use the performselector in OC, but I don't know why it was intentionally removed from SWIFT. Even more, even IMP and objc_msgsend cannot be used. Although I can't figure out why, I should have his reasons. Not
Fengsh998 original address: Sorry!
In the previous studies, the closure was originally understood as a block. Although there are many similarities, the block still has its own uniqueness. Recently, when writing OC/SWIFT mixed encoding, sometimes
Functions and closures functions and closures)
Use of functions
There is a significant difference between Function Definition and OC in swift. Use func to define the function, define the number and type of struct in brackets, and use-> to define
Note: As the basic part has been roughly described in swift tour, the explanation does not reach 100% of the original meaning.
Constants and variables constants and variables
Both constants and variables need to declare names and types (as
I mentioned the variables and constants without nutrition in the previous section. They are similar to each other. Just take a look at them.
Integer integer
An integer is an integer without decimal digits. The integer is signed (+,-, 0) or unsigned
I will continue with my lecture
Numeric literals numeric text
Digital text can be written in the following ways:
A decimal number, with no prefixA binary number, with a 0b prefixAn octal number, with a 0o prefixA hexadecimal number, with a 0x
Tag: swift Value Type
In swift, the struct and enumeration types are value types (structures and enumerations). In stack overflow, there is a problem:The variable attribute in the struct can be modified by the built-in method only after the mutating
Classes and struct have many commonalities:
Define attributes to store data
Define method execution function processing
Define subscripts and access their values through subscripts
Initialize their status
Extend its functions through
Enumerations)
EnumerationDefines a common group type for the values associated with a series, and allows you to use these values in case of type security during programming. If you are familiar with the C language, you must know thatEnumerationType
The added type in swift: tuple (tuples) allows you to create or transmit a group of data,
For example, when you return a function value, you can use a single tuple to return multiple values.
The optional (Optional) Type is added to swift to
3. conditional statements
It is often necessary to execute different codes according to different situations. You may want to execute an extra code when an error occurs, or output it to a value that is too high or too low. To meet these requirements,
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.