Self.view.frame.size.height = 100f; This cannot be compiled, the compiler will error "expression is not assignable"

Source: Internet
Author: User

self. View.frame.size.height = 100f; this cannot be compiled, and the compiler will error "expression is not assignable" because there are two different meanings of the points in this sentence. Self.view.frame is the objective-c syntax, is the frame property that reads the View property, using a point in objective-c to access the property is just a syntactic sugar, so self.view.frame this sentence will be converted to: [[Self View] frame In other words, this is actually a message delivery. The Frame property is a cgrect structure, so frame.size.height is the C language syntax, which is to access the Size field in the CGRect structure, and the height is a field of the cgsize structure. So, your sentence actually equals: [[self view] frame].size.height = 100f, and objective-c is just an extension of the C language, so the above sentence will be transferred to the C language function call form, similar to this form: GetFrame(). size. height = +f; in C, the return value of a function is a r-value, and it cannot be assigned directly (the so-called R-value, which can only appear to the right of the equal sign, you can understand as a constant While the l-value can be assigned, it can appear on the left side of the equal sign, usually a variable. Therefore, when you intend to assign a value directly to the return value of a function, the compiler tells you that "this expression cannot be assigned". This is the reason why the error occurred. So, the solution is to save the return value of the function with a temporary variable, modify the temporary variable, and then assign it to frame://1. Saves the return value with a temporary variable. CGRect temp = self.view.frame; 2. Assign a value to the variable. Since the variables are l-value, they can be assigned temp.size.height = 100f; 3. Modify the value of frame self.view.frame = temp;

Self.view.frame.size.height = 100f; this cannot be compiled, the compiler will error "expression is not assignable"

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.