Variable assignment for iOS instance class failed

Source: Internet
Author: User

Multiple encounters with similar problems are currently only found in the cause, in this record. When you find the solution, add it again.

Problem Description:

Declare Class A, Class B, main class M.

Declare an array of variables in Class A testarray;

@property (nonatomic, strong) Nsarray *testarray;

Instantiate Class A in the main class M, and add a view;

a *a = [[A alloc] Initwithframe:cgrectmake (0,0,20,20)];

[Self addsubview:a];

In class B, an instance of a gets an array of variables Testarray, and assigns values to the arrays;

a *a = [[a alloc] init];

A.testarray = @[@ "M", @ "n", @ "Q"];

The result is that the call array Testarray,testarray in Class A is empty and the assignment fails.

Reason:

The array testarray is called by different instances of Class A, and the allocated memory is different, so the array Testarray is assigned in Class B, and the array Testarray called in Class A is not the same number. Assignment failed.

Current Solution ideas:

1, to a type of single-case, to ensure that the project has only one instance of A; (if there are multiple singleton classes in the project, are there any drawbacks?) )

2. declare static array Testarray; (Test unsuccessful)

Variable assignment for iOS instance class failed

Related Article

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.