iOS recent company's face questions

Source: Internet
Author: User

1. How to modify the read-only (readonly) attribute variable
Using KVC can modify KVC is the key value encoding (Key-value), you can obtain the desired value by the specified key, but not by calling the Setter,getter method to access

2.KVO In addition to observing properties, can you observe the object
Object cannot be observed

KVO, Key-value Observing, provides a mechanism for the object to receive notification when the properties of the specified object have been modified. Simply put, the KVO will automatically notify the appropriate observer when the property of the object being specified is modified.

KVO is an object that can observe the value of a property of another object and be able to discover the change in value. This is one way to keep an object synchronized with another object, that is, when the state of another object changes, the observer responds immediately. It can only be used to react to attributes, not to react to methods or actions.

Implementation principle: When the listener is registered for an object property, the object's Isa pointer points to an intermediate class rather than to the original object's actual class. So, the object's Isa pointer can be changed, and our program is best not to rely on the ISA pointer.

The simple words are:

1. When an object has an observer, it does not dynamically create subclasses of this object's class

2. Override the Set method for each property that is observed

3. Called in the overridden set method-Willchangevalueforkey: And-Didchangevalueforkey: Notifies the Observer

4. When a property has no observer, delete the Override method

5. Delete dynamically created subclasses when a Boserver observes any property

3.block inside can modify static variable

Can __block can---> Why use __block

You can specify that a variable be introduced as a modifiable, read-write, modifier by applying the __block storage type.

__block of local variables are similar to storage types such as register,auto,static, but they are incompatible.

__block variables are stored within the scope of the variable share, and all blocks and block replicas are declared or created in the same scope as the variables. Therefore, if any blocks replica declaration does not exceed the end of the stack within the stack, the store will keep the stack frame from being destroyed (such as encapsulation for later execution). Multiple blocks given at the same scope can use a shared variable as an optimization at the same time, and the block is stored on top of the stack, just like the blocks itself. If a copy of block is copied using block_copy (or a copy message is sent to block inside the objective-c), the variable is copied to the heap. So the address of an __ block variable can change over time.

There are two limitations to using __block variables:

1. They cannot be variable-length arrays

2. They cannot be data structures that contain array variables with C99 variable sores

4. Declare a block

DECLARE block

Int (^myblock) (int)

Description: The first int is the return value of Block Myblock is the block variable the second int is the parameter

void (^myblock) (int-(void) Setmyblock: (void(^) (int value)) block;

    
-(void) Setmyblock: (void(^) (int  value)) block {     if  ( Block) {    Self.block=block;    }}

5. When using CoreData, if the user updates personal information, how to use the code to update the personal information displayed on the page

1. When the user updates their own user information, save the updated data to the database

2. When the user returns to update the page, the contents of the database are queried and displayed on the page.

Query Database code:

    

//Create requestNsfetchrequest *request =[[Nsfetchrequest alloc] init];//Create an entity descriptionNsentitydescription *entity =[Nsentitydescription entityForName:ENTITY_NAMEinManagedObjectContext:content]; [Request setentity:entity]; [Request Setreturnsobjectsasfaults:no];//SET predicateNspredicate *predicate = [Nspredicate predicatewithformat:@"Self =%@", data]; [Request Setpredicate:predicate];//Execute RequestNsarray *dataarray =[content executefetchrequest:request Error:nil];//Modify Informationif([DataArray Count] >0) {tasktypeentity*tasktypeentity = [DataArray objectatindex:0]; Tasktypeentity.color =Data.color;tasktypeentity.status=Data.status;tasktypeentity.image=Data.image;tasktypeentity.name= Data.name; BOOL result =[content Save:nil];if(Result) {NSLog (@ "");         }Else{NSLog (@" "); }}

   after the data is saved successfully, update the data directly after you repeat the above step query on the Personal Information display page                           

iOS recent company's face questions

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.