Method and device for adding iOS classification attribute, electronic equipment and storage medium
By using macro code files to automatically generate iOS category attributes, the problem of excessively large installation packages and errors caused by manually writing implementation methods in iOS project development is solved, resulting in smaller installation packages and higher code accuracy.
Patent Information
- Application Number
- CN202211192990.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-28
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2042-09-28
AI Technical Summary
In iOS project development, when adding properties using Objective-C category features, manually writing implementation methods results in excessively large installation packages, is prone to errors, and cannot dynamically add member variables at runtime.
The system generates macro code files for object types and basic data types from a preset base macro code file. It automatically generates a declaration configuration code file package based on the category name and attribute description, and replaces the target macro code file to achieve the addition of iOS category attributes.
It reduces the size of the installation package for iOS project development, improves code accuracy, reduces the possibility of human error, and simplifies the process of adding attributes.
Smart Images

Figure CN115437619B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of software technology, and more particularly to a method and apparatus for adding iOS category attributes, an electronic device, and a storage medium. Background Technology
[0002] Currently, Objective-C's category feature is frequently used in iOS project development to add new methods to instance objects or class objects, and sometimes it's also necessary to add properties to categories. Categories can have properties added, but member variables and method implementations are not automatically generated.
[0003] If you want to add category member variables to the struct of an instance object at runtime, you need to use the associated runtime API to indirectly achieve the effect of adding member variables. After adding attributes to a category, there are no implemented methods by default. Implementing methods requires manually writing code, which involves a lot of code, resulting in a large installation package for iOS projects. Furthermore, manually writing code is prone to errors and not conducive to widespread application. Summary of the Invention
[0004] The main objective of this application is to provide a method, apparatus, electronic device, and storage medium for adding iOS category attributes, aiming to reduce the size of the installation package in iOS project development, improve the accuracy of the installation package code, and facilitate its widespread application.
[0005] To achieve the above objectives, a first aspect of this application proposes a method for adding iOS category attributes, the method comprising:
[0006] Based on a preset basic macro code file, a first macro code file for object type attributes and a second macro code file for basic data type attributes are obtained; the basic macro code file contains the implementation methods for variable attributes;
[0007] Based on the first macro code file and the second macro code file, determine the set of code files to be declared;
[0008] Based on the category name and variable attribute description of the iOS category, obtain the declaration configuration code file package of the iOS category from the set of code files to be declared;
[0009] Based on the declared configuration code file package, obtain the target macro code file installation package corresponding to the category name and the attribute description of the variable attribute;
[0010] Based on the target macro code file installation package, add the category attributes for the iOS.
[0011] In some embodiments, the first macro code file for the object type attribute includes a macro code file configuring strong reference attributes, and the base macro code file includes a strong reference type macro code file. The macro code file configuring strong reference attributes is determined by the following method:
[0012] Define the strong reference type macro code file, which includes the names of access methods and caching strategies;
[0013] The macro code file for configuring strong reference attributes is determined based on the strong reference type macro code file.
[0014] In some embodiments, the first macro code file for the object type attribute includes a macro code file configuring the weak reference attribute, and the base macro code file includes a weak reference type macro code file. The macro code file configuring the weak reference attribute is determined by the following method:
[0015] Define the weak reference type macro code file, which includes the names of the access methods;
[0016] The macro code file for configuring weak reference attributes is determined based on the weak reference type macro code file.
[0017] In some embodiments, the base macro code file includes a non-object type macro code file, and the second macro code file for the basic data type attribute is determined by the following method:
[0018] Define the non-object type macro code file, which includes the names of the access methods and the data type conversion methods;
[0019] The second macro code file is determined based on the non-object type macro code file to identify the basic data type attributes.
[0020] In some embodiments, obtaining the declaration configuration code file package of the iOS category from the set of content code files to be declared, based on the category name and attribute description of the variable attributes of the iOS category, specifically includes:
[0021] Based on the attribute description of the variable attribute, obtain the corresponding declaration content file type from the set of content files to be declared;
[0022] The iOS declaration configuration code file is determined based on the file type of the declaration content and the category name of the iOS category;
[0023] The declaration configuration code file package is obtained based on the declaration configuration code file and the declaration implementation code file.
[0024] In some embodiments, obtaining the target macro code file installation package corresponding to the category name and the attribute description of the variable attribute based on the declared configuration code file package specifically includes:
[0025] Based on the attribute description of the variable attribute, obtain the corresponding target macro file type;
[0026] Based on the target macro file type and the category name, obtain the target macro code file from the first macro code file and / or the second macro code file;
[0027] The target macro code file installation package is obtained based on the target macro code file and the macro implementation code file.
[0028] In some embodiments, the category name of the iOS category is determined by the following method:
[0029] Determine the category corresponding to the iOS category;
[0030] The category name of the iOS category is determined based on the name of the class.
[0031] To achieve the above objectives, a second aspect of this application provides an apparatus for adding iOS category attributes, the apparatus comprising:
[0032] The first module is used to obtain a first macro code file for object type attributes and a second macro code file for basic data type attributes based on a preset basic macro code file; the basic macro code file contains the implementation methods for variable attributes;
[0033] The second module is used to determine the set of code files to be declared based on the first macro code file and the second macro code file;
[0034] The third module is used to obtain the declaration configuration code file package of the iOS category from the set of code files to be declared based on the category name and attribute description of the variable attributes of the iOS category.
[0035] The fourth module is used to configure the code file package according to the declaration, and obtain the target macro code file installation package corresponding to the category name and the attribute description of the variable attribute;
[0036] The fifth module is used to add the category attributes of the iOS based on the target macro code file installation package.
[0037] To achieve the above objectives, a third aspect of this application provides an electronic device, which includes a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for enabling communication between the processor and the memory. When the program is executed by the processor, it implements the method described in the first aspect above.
[0038] To achieve the above objectives, a fourth aspect of the present application provides a storage medium, which is a computer-readable storage medium for computer-readable storage, wherein the storage medium stores one or more programs that can be executed by one or more processors to implement the method described in the first aspect.
[0039] The iOS category attribute addition method, device, electronic device, and storage medium proposed in this application obtain a first macro code file for object type attributes and a second macro code file for basic data type attributes through a preset basic macro code file. Based on the first and second macro code files, a set of content code files to be declared is determined. Based on the category name and attribute description of the variable attributes of the iOS category, an iOS category declaration configuration code file package is obtained from the set of content code files to be declared. Based on the declaration configuration code file package, a corresponding target macro code file installation package is obtained. The iOS category attributes are added based on the target macro code file installation package. The basic macro code file includes the implementation method of the variable attributes. When the target macro code file installation package is run, the target macro code file in the installation package is first replaced by the first macro code file for object type properties and / or the second macro code file for basic data type properties. Then, the first macro code file for object type properties and / or the second macro code file for basic data type properties are replaced by the preset base macro code file. This macro replacement reduces the amount of code segments, thereby reducing the size of the installation package for iOS projects and facilitating application promotion. In addition, macro replacement reduces the need for manual coding, improving the accuracy of the installation package code and further reducing application crashes caused by missing implementation methods. Furthermore, during the process of adding iOS category attributes, macros are used to perform text replacement on the code during the program preprocessing stage before the source code is compiled, enabling the addition of iOS category attributes using the above methods. Attached Figure Description
[0040] Figure 1 This is a flowchart of the method for adding iOS category attributes provided in the embodiments of this application;
[0041] Figure 2 yes Figure 1 The flowchart of the method for determining the macro code file for configuring strong reference attributes in step S101;
[0042] Figure 3 yes Figure 1 The flowchart of the method for determining the macro code file for configuring weak reference attributes in step S101;
[0043] Figure 4 yes Figure 1 A flowchart illustrating the method for determining the second macro code file for basic data type attributes in step S101;
[0044] Figure 5 yes Figure 1 The flowchart of the method for determining the iOS category declaration configuration code file package in step S103;
[0045] Figure 6 yes Figure 1 The flowchart of the method for determining the target macro code file installation package in step S104;
[0046] Figure 7 yes Figure 1 The flowchart of the method for determining the category name in step S103;
[0047] Figure 8 This is a schematic diagram of the structure of the iOS category attribute adding device provided in the embodiments of this application;
[0048] Figure 9 This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0049] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0050] It should be noted that although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first," "second," etc., in the specification, claims, and the aforementioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0051] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0052] First, some relevant knowledge related to the subject matter involved in this application will be explained.
[0053] Objective-C is an object-oriented programming language where every object is an instance of a class. Internally, each object in Objective-C has a pointer named `isa` that points to the object's class. Each class describes a set of characteristics of its instances, including a list of member variables and member functions. Every object can receive messages, and the list of messages an object can receive is stored in its corresponding class. In Objective-C, each class actually has one object, each class also has a pointer named `isa`, and each class can also receive messages.
[0054] If we consider an instance of a class as a C language struct, the `isa` pointer is the first member variable of this struct, with the other member variables arranged sequentially within the struct. The object's arrangement in memory can be viewed as a loosely structured entity; the size of this struct cannot change dynamically, and member variables cannot be added to the object at runtime. Correspondingly, the object's method definitions are stored in the class's mutable area. By modifying the value of the pointer pointed to by this pointer, member methods can be dynamically added to a class.
[0055] In iOS development, reference relationships such as strong and weak references are involved, along with corresponding execution instructions. When defining a property, declaring it as `retain` indicates a strong reference; declaring it as `assign` indicates a weak reference. In memory management, a strong reference is declared as `strong`, and a weak reference is declared as `weak`. In other words, `retain` and `strong` are essentially the same (declaring a strong reference), and `assign` and `weak` are largely the same (declaring a weak reference).
[0056] Strong references: When the current object is strongly referenced by another object, a retain operation is performed. If the current object is strongly referenced by another object, the reference counter retainCount is incremented by 1; if the strong reference to the current object is released, the reference counter retainCount is incremented by 1. The object is only destroyed when retainCount = 0. Due to the need for object memory management, strong references are generally used by default.
[0057] Weak references: The lifecycle of the current object is not limited by whether it is referenced by other objects, and the assign operation is performed. It is automatically destroyed when its lifecycle expires; even if its references are not broken, it will still be destroyed when its lifecycle expires. Additionally, the assign operation is used for the definition of data types.
[0058] Based on this, embodiments of this application provide a method and apparatus for adding iOS category attributes, an electronic device, and a storage medium, which aim to reduce the size of the installation package in iOS project development, improve the accuracy of the installation package code, and facilitate its widespread application.
[0059] The iOS category attribute addition method, apparatus, electronic device, and storage medium provided in this application are specifically described through the following embodiments. First, the iOS category attribute addition method in this application embodiment is described.
[0060] The method for adding iOS category attributes provided in this application relates to the field of software technology. This method can be applied to a terminal, a server, or software running on either a terminal or a server. In some embodiments, the terminal can be a smartphone, tablet, laptop, desktop computer, etc.; the server can be configured as an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application implementing the method for adding iOS category attributes, but is not limited to the above forms.
[0061] This application can be used in a wide variety of general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0062] When adding category attributes in iOS, member variables don't exist in the underlying `category_t` struct; they are stored in the instance object and determined at compile time, while categories are loaded at runtime. Therefore, it's impossible to add category member variables to the instance object's struct at runtime. In this case, the associated runtime API is needed to indirectly achieve the effect of adding member variables. After adding attributes to a category, there are no implemented methods by default; implementation methods are typically created manually through coding.
[0063] The first step in compiling a C program is the preprocessing stage, where macro definitions take effect. The C preprocessor performs some "textual" operations on the source code before compilation. Its main tasks include removing comments, inserting content from #included files, defining and replacing symbols defined by #define, and determining whether certain parts of the code should be conditionally compiled. These "textual" operations mean replacing one piece of text with another, regardless of any semantic meaning. Macros are merely text substitution tools during the C preprocessing stage and are not visible in the binary code after compilation.
[0064] This application defines some basic macros, determines macros for object type attributes and macros for basic data types based on the basic macros, and adds iOS category attributes by declaring and executing macros for object type attributes and macros for basic data types corresponding to iOS category attributes.
[0065] A macro is a term for batch processing; in computer science, a macro is an abstraction that replaces certain text patterns according to a set of predefined rules. The interpreter or compiler automatically performs this pattern replacement when it encounters a macro. For compiled languages, macro expansion occurs at compile time, and the tool that performs macro expansion is often called a macro expander. Because macro expansion is essentially a preprocessing step for the editor, it can control the program source code itself and the compilation process at a higher level. It is this characteristic that gives macros their powerful functionality and flexibility.
[0066] The method for adding iOS category attributes in this embodiment of the invention can be applied to a variety of application scenarios, such as adding code blocks, delegate callbacks and other attributes to system classes such as UI libraries and basic libraries to achieve functional expansion.
[0067] Figure 1 This is an optional flowchart of the iOS category attribute addition method provided in the embodiments of this application. Figure 1 The method may include, but is not limited to, steps S101 to S105.
[0068] Step S101: Obtain a first macro code file for object type attributes and a second macro code file for basic data type attributes based on a preset basic macro code file; the basic macro code file contains the implementation method of variable attributes.
[0069] Step S102: Determine the set of code files to be declared based on the first macro code file and the second macro code file.
[0070] Step S103: Based on the category name and variable attribute description of the iOS category, obtain the declaration configuration code file package of the iOS category from the set of code files to be declared.
[0071] Step S104: Based on the declared configuration code file package, obtain the target macro code file installation package corresponding to the category name and the attribute description of the variable attribute.
[0072] Step S105: Add the category attributes of the iOS according to the target macro code file installation package.
[0073] It should be noted that the preset basic macro code file includes macros of various types for adding corresponding categories of attributes involved in iOS project development. The basic macros define basic variables and implementation methods. Macros for object type attributes and basic data type attributes can be determined based on the basic macros. The basic macros are updated according to actual applications, such as adding or deleting them.
[0074] It should be noted that the first macro code file defining object type properties and the second macro code file defining basic data type properties have added operation instructions to the referenced basic macros.
[0075] It should be noted that the set of code files to be declared includes various types of first macro code files and second macro code files.
[0076] Steps S101 to S105 as illustrated in this embodiment involve: Step S101 defining a first macro code file for object type attributes and a second macro code file for basic data type attributes by referencing preset basic macros; Step S102 combining multiple first macro code files and second macro code files to form a set of content code files to be declared; Step S103 matching the corresponding declaration content from the set of content code files to be declared based on the iOS category name and variable attribute description, and performing parameter specification to obtain a declaration configuration code file package; Step S104 specifying the target macro content corresponding to the declaration content of the declaration configuration code file package, and performing parameter specification or obtaining a target macro installation package; and finally, Step S105 installing and running the target macro code file installation package to complete the addition of iOS category attributes.
[0077] The basic macro code files include, but are not limited to, macro code files for strong reference types, macro code files for weak reference types, and macro code files for non-object types. The first macro code file for object type properties includes, but is not limited to, macro code files for configuring strong reference properties, macro code files for configuring weak reference properties, or macro code files for copying reference properties. There is a correspondence between the basic macro code files and the first or second macro code files, and the content defined in different basic macro code files is different.
[0078] Macro definition is one of the three preprocessing functions provided by C, which include macro definition, file inclusion, and conditional compilation. Macros in C system development are divided into two categories: object-like macros and function-like macros. Object macros are indeed relatively simple. The `#define` keyword indicates that a macro definition is about to begin. For example, `#define XA`. This object macro is relatively simple. During compilation, the compiler will identify it as a macro through semantic analysis and replace `X` with `A`. This process is called macro expansion. Function macros, as the name suggests, behave like functions and can accept parameters. Specifically, if a pair of parentheses follows the macro name during definition, the macro becomes a function macro. For example, `#define SE(X)X`. This macro does the following: during compilation, if it encounters `SE` followed by parentheses, and the number of parameters in the parentheses matches the definition, it will replace the original content with the parameters in the parentheses. The macros used in this application are function macros.
[0079] The format of an object macro is: #define macro_name(parameter_list) string. The following issues should be noted during the definition of an object macro: (1) Macro names are generally in uppercase; (2) Using macros can improve the versatility and readability of the program, reduce inconsistencies, reduce input errors and facilitate modification; for example, array size is often defined by macros; (3) Preprocessing is the processing before compilation, and one of the tasks of compilation is syntax checking. Preprocessing does not perform syntax checking; (4) No semicolon is added at the end of the macro definition; (5) The macro definition is written outside the curly braces of the function, and its scope is the program that follows it, usually at the beginning of the file; (6) The scope of the macro definition can be terminated by the #undef command; (7) Macro definitions can be nested; (8) The string "" never contains macros; (9) Macro definitions do not allocate memory, while variable definitions do.
[0080] In addition to general string replacement, function macros also need to perform parameter substitution. The format of a function macro is: #define macro_name(parameter_list) string. For example: #define S(a,b)a*b area=S(3,2); the first step is replaced with area=a*b; the second step is replaced with area=3*2; similar to a function call, there is a process of combining dummy and actual parameters: (1) If the actual parameter is an expression, it is easy to cause problems. #define S(r)r*r area=S(a+b); the first step is replaced with area=r*r, the second step is replaced with area=a+b*a+b. The correct macro definition is #define S(r)((r)*(r)); (2) There should be no space between the macro name and the parentheses of the parameter; (3) Macro substitution only performs substitution, does not perform calculation, and does not perform expression evaluation; (4) Function calls are performed after compilation and the program is running, and memory is allocated; macro substitution is performed before compilation and memory is not allocated; (5) The dummy and real combination of macros does not have a type and there is no type conversion; (6) A function has only one return value, but multiple values can be obtained by using macros; (7) Macro expansion makes the source program longer, while function calls do not; (8) Macro expansion does not take up runtime, only compilation time, while function calls take up runtime (memory allocation, saving context, value passing, return value).
[0081] In some specific implementations, the basic macros include three macros named AISSynthesizeId, _AISSynthesizeWeakId, and _AISSynthesizeNonObject. AISSynthesizeId, _AISSynthesizeWeakId, and _AISSynthesizeNonObject can be named freely according to naming rules and the meaning of the attribute variables. _AISSynthesizeId uses _getterName, _setterName, and _policy as parameters to configure the reference attribute, configuring the name of the getter method, the name of the setter method, and the reference type, respectively; where getterName is the name of the getter method, _setterName is the name of the setter method, and _policy is the related policy for associative references. _AISSynthesizeWeakId uses _getterName and _setterName as parameters to configure the weak reference attribute; where _getterName is the name of the getter method, and _setterName is the name of the setter method. AISSynthesizeNonObject uses _getterName, _setterName, _type, valueInitializer, and valueGetter as configuration parameters for non-object types. Among them, getterName is the name of the getter method, _setterName is the name of the setter method, _type is the basic data type, such as Int for integers and Float for floating-point numbers; valueInitializer is the name of the method that converts the basic data type to NSNumber; and valueGetter is the name of the method that converts NSNumber to the basic data type.
[0082] In some specific implementations, the header file defining the basic macros is as follows.
[0083] Strong reference type: #define_AISSynthesizeId(_getterName,_setterName,_policy)\.
[0084] Weak reference type: #define_AISSynthesizeWeakId(_getterName,_setterName)\.
[0085] Non-object type: #define_AISSynthesizeNonObject(_getterName,_setterName,_type,valueInitializer,valueGetter)\.
[0086] Please see Figure 2 In some embodiments, the method for determining the macro code file with strong reference attributes in step 101 may include, but is not limited to, steps S201 to S202.
[0087] Step S201: Define the strong reference type macro code file, which includes the name of the access method and the caching strategy;
[0088] Step S202: Determine the macro code file for configuring strong reference attributes based on the strong reference type macro code file.
[0089] It should be noted that access methods include getter methods and setter methods. Strong reference type macros define getter methods, setter methods, and caching strategies, etc. The file header includes the parameter getter method name, setter method name, and related strategies for associated references.
[0090] Specifically, first, the header file and implementation process of the strong reference type macro are defined. Then, based on the names of the strong reference type macro and the accessor methods, the macros that configure strong reference properties are determined. The operation corresponding to the strong reference type macro is RETAIN.
[0091] In a specific implementation, if the header file for a strong reference type is: `#define _AISSynthesizeId(_getterName,_setterName,_policy)`, then the macro `AISSynthesizeIdStrongProperty` that configures the strong reference property is:
[0092] / / / @property(nonatomic,strong)id xxx
[0093] #define AISSynthesizeIdStrongProperty(_getterName1,_setterName1)_AISSynthesizeId(_getterName1,_setterName1,RETAIN)
[0094] Specifically, the definition of a strong reference type macro is as follows:
[0095]
[0096] Where _getterName is the name of the getter method, _setterName is the name of the setter method, and _policy is the policy related to the associative reference, an enumeration type defined as follows:
[0097]
[0098] Specifically, preprocessing is a text processing step that uses the source file's text as the first stage of translation. Preprocessing does not analyze the source text, but it breaks it down into tags to find macro calls. It mainly includes the following three aspects: preprocessing directives, preprocessing operators, and predefined macros.
[0099] The `#pragma` directive is used to specify computer- or operating system-specific compiler features. Each implementation of C and C++ supports certain features unique to its host or operating system. For example, some programs must have precise control over the memory regions where data is placed or how certain functions receive arguments. While maintaining overall compatibility with the C and C++ languages, the `#pragma` directive enables each compiler to provide computer- and operating system-specific features. By definition, `#pragma` directives are computer- or operating system-specific and typically differ from compiler to compiler. `#pragma` directives can be used with conditional statements to provide new preprocessor features or to provide the compiler with implementation-defined information. After `#pragma`, the compiler transformer can analyze all text as preprocessor tags. The arguments of `#pragma` are subject to macro expansion; if the compiler finds a miscellaneous annotation it cannot recognize, it will issue a warning and continue compilation.
[0100] Furthermore, the macros configuring copy properties in object type property macros are also determined based on the strong reference type macros. For example, in a specific implementation, if the header file for a strong reference type is: `#define _AISSynthesizeId(_getterName,_setterName,_policy)`, then the macro configuring the copy property `AISSynthesizeIdCopyProperty` is:
[0101] / / / @property(nonatomic,copy)id xxx
[0102] #define AISSynthesizeIdCopyProperty(_getterName2,_setterName2)_AISSynthesizeId(_getterName2,_setterName2,COPY)
[0103] Please see Figure 3 In some embodiments, the method for determining the macro code file that configures the weak reference attribute in step S101 includes, but is not limited to, steps S301 to S302.
[0104] Step S301: Define the weak reference type macro code file, wherein the weak reference type macro code file includes the name of the access method;
[0105] Step S302: Determine the macro code file for configuring weak reference attributes based on the weak reference type macro code file.
[0106] It should be noted that access methods include getter methods and setter methods. The weak reference type macro defines the getter methods and setter methods, and the file header includes the names of the parameter getter method and the name of the setter method.
[0107] Specifically, first, the header file and implementation process of the weak reference type macro are defined, and then the macro for configuring the weak reference property is determined based on the name of the weak reference type macro and the accessor method.
[0108] In a specific implementation, if the header file for a weak reference type is: `#define _AISSynthesizeWeakId(_getterName, _setterName)`, then the macro `AISSynthesizeIdWeakProperty` that configures the weak reference property is:
[0109] / / / @property(nonatomic,weak)id xxx
[0110] #define AISSynthesizeIdWeakProperty(_getterName3,_setterName3)_AISSynthesizeWeakId(_getterName3,_setterName3)
[0111] Specifically, the definition of the weak reference type macro is as follows:
[0112]
[0113] Where _getterName is the name of the getter method and _setterName is the name of the setter method.
[0114] Please see Figure 4In some embodiments, the method for determining the second macro code file of the basic data type attributes in step S101 includes, but is not limited to, steps S401 to S402.
[0115] Step S401: Define the non-object type macro code file, which includes the name of the access method and the data type conversion method;
[0116] Step S402: Determine the second macro code file for the basic data type attribute based on the non-object type macro code file.
[0117] It should be noted that the data types include, but are not limited to, int, unsigned int, float, double, boolean types, NSInteger, NSUInteger, CGFloat, CGPoint, CGSize, CGRect, UIEdgeInsets, CGVector, and CGAffineTransform, each of which is defined separately.
[0118] Specifically, first, the header files for non-object type macros and data type conversion methods are defined, and then the macros for basic data type attributes are determined based on the names of the non-object type macros and data type conversion methods.
[0119] In a specific implementation, taking integers as an example, if the header file for non-object types is: `#define _AISSynthesizeNonObject(_getterName,_setterName,_type,valueInitializer,valueGetter)`, then the macro for basic data type properties is:
[0120] / / / @property(nonatomic,assign)Int xxx is used for int type
[0121] #define AISSynthesizeIntProperty(_getterName4,_setterName4)_AISSynthesizeNonObject(_getterName4,_setterName4,int,numberWithInt,intValue)
[0122] The definitions of non-object type macros are as follows:
[0123]
[0124] Where _getterName is the name of the getter method, _setterName is the name of the setter method, _type is the basic data type, such as Int for integer and Float for floating-point, valueInitializer is the name of the method that converts the basic data type to NSNumber, and valueGetter is the name of the method that converts NSNumber to the basic data type.
[0125] Please see Figure 5 In some embodiments, step S103, which involves obtaining the declaration configuration code file package of the iOS category from the set of code files to be declared based on the category name and attribute description of the variable attributes of the iOS category, specifically includes, but is not limited to, steps S501 to S503.
[0126] Step S501: Obtain the corresponding declaration content file type from the set of content files to be declared according to the attribute description of the variable attribute;
[0127] Step S502: Determine the iOS declaration configuration code file based on the declaration content file type and the category name of the iOS category;
[0128] Step S503: Obtain the declaration configuration code file package based on the declaration configuration code file and the declaration implementation code file.
[0129] Specifically, firstly, based on the attribute description of the variable, the corresponding declaration content file type is obtained from the set of content files to be declared. For example, if the attribute description is a strong reference to an object type, the declaration content file type corresponding to the strong reference to an object type is matched from the set of content files to be declared as a strong reference declaration type. Then, the category name of the iOS category determines the file parameters in the declaration content file type to obtain the iOS declaration configuration code file. Then, based on the beginning and ending files of the declaration implementation code file, the declaration configuration code file package is obtained by combining the declaration configuration code file.
[0130] In some embodiments, adding attributes strongControllerA, weakControllerA, nameA, and integerA to the category of a ViewController is taken as an example. Step S101 declares the iOS category attributes as follows:
[0131] @interface ViewController(A)
[0132] @property(nonatomic,strong)ViewController*strongControllerA;
[0133] @property(nonatomic,weak)ViewController*weakControllerA;
[0134] @property(nonatomic,copy)NSString*nameA;
[0135] @property(nonatomic,assign)NSInteger integerA;
[0136] @end
[0137] In this code, `@interface` is the declaration section, `@property` is the property description section, `nonatomic` indicates a non-fixed format, `atomic` indicates a fixed format, `atomic` is the default mode, and `@end` is the closing section. `ViewController` represents the class name, `ViewController(A)` represents the category name of this class, `strongControllerA`, `weakControllerA`, `nameA`, and `integerA` represent the names of variable properties, and `strong`, `weak`, `copy`, and `assign` are used to describe related properties, such as `strong` indicating strong reference, `weak` indicating weak reference, and `copy` indicating copy.
[0138] Specifically, the format of @property is: @property(parameter1, parameter2, ...) type name, for example, @property(nonatomic, strong)ViewController*strongControllerA. The parameters are mainly divided into three categories: read-write properties (readwrite / readonly / setter= / getter=), setter semantics (assign / retain / copy), atomicity (atomicity / nonatomic), and nullability annotations (nonnull / nullable).
[0139] The parameters have the following meanings: `readwrite` generates setter and getter methods; `readonly` generates only a simple getter, no setter, the default read-write property; `setter` specifies the name of the generated setter method; `getter` specifies the name of the generated getter method; `assign` is the default type, the setter method directly assigns the value without retaining it, suitable for primitive data types and object types, and will not change the reference count; `retainsetter` releases the old value of the parameter and then retains the new value; `copysetter` performs a copy operation, similar to retain; `atomic` ensures safety under multi-threaded access, but wastes system resources; the default setting for atomicity control; `nonatomic` disables multi-threading, protects variables, and improves performance; `nonnull` indicates that the object can be NULL, or `nil-nullable` indicates that the object should not be null.
[0140] The difference between `atomic` and `nonatomic` is as follows: `atomic` is the default property, indicating that operations on an object are atomic. It primarily provides thread safety in a multi-threaded environment. In a multi-threaded world, accessing an object requires locking and unlocking to ensure that multiple operations do not target the same object simultaneously. If multi-threading is not involved in the program, it is not recommended to use `atomic` because it consumes more system resources than `nonatomic`. `nonatomic` indicates that access to the accessor is not atomic and does not support thread safety, but it offers higher performance.
[0141] `retain` means releasing the old value and retaining the new value for NSObject and its subclasses, incrementing the reference count of the object by one. This property can only be used on Objective-C type objects, not Core Foundation objects. `assign` is the default property and can only be used on primitive data types (such as CGFloat, NSInteger, Bool, int, etc.). This method directly assigns the object without performing a retain operation. `copy` means creating a new object with a reference count of 1 and then releasing the old value. `retain` copies the pointer, while `copy` copies the content. That is, `retain` copies the pointer, and `copy` copies the content; both release the old object before copying. `assign` is a simple assignment that does not change the reference count. `copy` creates an object with a reference count of 1, then releases the old object; `retain` releases the old object, assigns the old object's value to the input object, and then increments the reference count of the input object to 1.
[0142] The purpose of including `strong` and `weak` in object declarations is to facilitate automatic memory management. `strong` represents a strong reference, a default property similar to `retain`. By default, all instance variables and local variables are `strong` pointers. If a strong reference holds the object, the object cannot be released. `weak` represents a weak reference, similar to `assign`. A weak reference is the same as a strong reference except that it doesn't determine the object's existence; even if an object has numerous weak references, it will still be cleared as long as no strong reference points to it. It is not the owner of the object, and its value is automatically set to `nil` after the object is released. Weak pointers are mainly used in "parent-child" relationships. The parent owns a strong pointer to the child, therefore the parent is the owner of the child; however, to prevent a cycle of ownership, the child needs to use a weak pointer to point to the parent. For example, a typical example is the delegate pattern, where the ViewController owns a UITableView's dataSource through a strong pointer (`self.view`), and the delegate is a weak pointer.
[0143] Specifically, `copy` is used with NSString and block; `assign` is used with delegate, int, float, NSInteger, bool, enumerations, structs, etc.; `retain` is used with NSArray, NSDate, etc.; `strong` is used with Objective-C objects other than NSString / block; `weak` is used when two objects reference each other, one using `strong` and the other using `weak`; `readOnly` is used when the object is read-only (i.e., only getter methods are needed); `readWriete` is used for default properties (getter and setter methods).
[0144] Please see Figure 6 In some embodiments, the step S104, which involves configuring the code file package according to the declaration and obtaining the target macro code file installation package corresponding to the category name and the attribute description of the variable attribute, specifically includes, but is not limited to, steps S601 to S603.
[0145] Step S601: Obtain the corresponding target macro file type according to the attribute description of the variable attribute;
[0146] Step S602: Obtain the target macro code file from the first macro code file and / or the second macro code file according to the target macro file type and the category name;
[0147] Step S603: Obtain the target macro code file installation package based on the target macro code file and the macro implementation code file.
[0148] It should be noted that the category name matches the implementation name of the macro corresponding to the declaration content. The target macro code file corresponds one-to-one with the contents of the declaration configuration code file package; the target macro code file is the implementation process of the variable attributes in the declaration configuration code file package.
[0149] Specifically, firstly, the target macro file type is obtained based on the attribute description of the variable attribute. For example, if the attribute description is a strong reference to an object type, the target macro file type corresponding to the first macro code file is determined to be a macro code file with a strong reference attribute configured based on the strong reference to the object type. Then, the file parameter in the target macro file type is determined by the category name of the iOS category to obtain the target macro code file. Finally, the target macro code file installation package is obtained by combining the beginning and end files of the target macro code file with the target macro code file.
[0150] In some embodiments, the specific contents of the target macro code file installation package are as follows:
[0151] @implementation ViewController(A)
[0152] AISSynthesizeIdStrongProperty(strongControllerA,setStrongControllerA)
[0153] AISSynthesizeIdWeakProperty(weakControllerA,setWeakControllerA)
[0154] AISSynthesizeIdCopyProperty(nameA,setNameA)
[0155] AISSynthesizeIntProperty(integerA,setIntegerA)
[0156] @end
[0157] Here, `@implementation` declares the implementation, `@end` is the closing part, `ViewController(A)` represents the category name of this class, `AISSynthesizeIdStrongProperty`, `AISSynthesizeIdWeakProperty`, and `AISSynthesizeIdCopyProperty` are all macros defining object type properties. `AISSynthesizeIdStrongProperty` is a macro for configuring strong reference properties, `AISSynthesizeIdWeakProperty` is a macro for configuring weak reference properties, `AISSynthesizeIdCopyProperty` is a macro for configuring copy properties, and `AISSynthesizeIntProperty` is a macro for basic data type properties.
[0158] It should be noted that since AISSynthesizeIdStrongProperty, AISSynthesizeIdWeakProperty, AISSynthesizeIdCopyProperty, and AISSynthesizeIntProperty are macros of object type properties or macros of basic data type properties, during code execution, the macros of object type properties or macros of basic data type properties are replaced with the corresponding basic macros, and the basic macros are replaced with the corresponding code.
[0159] Please see Figure 7In some embodiments, the method for determining the category name in step S103 may include, but is not limited to, steps S701 to S702.
[0160] Step S701: Determine the category corresponding to the iOS category;
[0161] Step S702: Determine the category name of the iOS category based on the name of the current category.
[0162] Specifically, first, the corresponding class is determined based on the specific content of the added iOS category attribute. Then, the category name is determined based on the name of the class. There are no restrictions on the specific method used to determine the category name based on the class name; for example, the class name can be extended to AB or A(C), etc.
[0163] It should be noted that determining the category name based on the name of this class makes it easier to associate this class with the category and to distinguish between different categories.
[0164] The iOS category attribute addition method, device, electronic device, and storage medium proposed in this application obtain a first macro code file for object type attributes and a second macro code file for basic data type attributes through a preset basic macro code file. Based on the first and second macro code files, a set of content code files to be declared is determined. Based on the category name and attribute description of the variable attributes of the iOS category, an iOS category declaration configuration code file package is obtained from the set of content code files to be declared. Based on the declaration configuration code file package, a corresponding target macro code file installation package is obtained. The iOS category attributes are added based on the target macro code file installation package. The basic macro code file includes the implementation method of the variable attributes. When the target macro code file installation package is run, the target macro code file in the installation package is first replaced by the first macro code file for object type properties and / or the second macro code file for basic data type properties. Then, the first macro code file for object type properties and / or the second macro code file for basic data type properties are replaced by the preset base macro code file. This macro replacement reduces the amount of code segments, thereby reducing the size of the installation package for iOS projects and facilitating application promotion. In addition, macro replacement reduces the need for manual coding, improving the accuracy of the installation package code and further reducing application crashes caused by missing implementation methods. Furthermore, during the process of adding iOS category attributes, macros are used to perform text replacement on the code during the program preprocessing stage before the source code is compiled, enabling the addition of iOS category attributes using the above methods.
[0165] Please see Figure 8This application embodiment also provides an iOS category attribute adding device, which can implement the above-described iOS category attribute adding method. The device includes:
[0166] The first module is used to obtain a first macro code file for object type attributes and a second macro code file for basic data type attributes based on a preset basic macro code file; the basic macro code file contains the implementation methods for variable attributes;
[0167] The second module is used to determine the set of code files to be declared based on the first macro code file and the second macro code file;
[0168] The third module is used to obtain the declaration configuration code file package of the iOS category from the set of code files to be declared based on the category name and attribute description of the variable attributes of the iOS category.
[0169] The fourth module is used to configure the code file package according to the declaration, and obtain the target macro code file installation package corresponding to the category name and the attribute description of the variable attribute;
[0170] The fifth module is used to add the category attributes of the iOS based on the target macro code file installation package.
[0171] The specific implementation of the iOS category attribute adding device is basically the same as the specific implementation of the iOS category attribute adding method described above, and will not be repeated here.
[0172] The iOS category attribute addition method, device, electronic device, and storage medium proposed in this application obtain a first macro code file for object type attributes and a second macro code file for basic data type attributes through a preset basic macro code file. Based on the first and second macro code files, a set of content code files to be declared is determined. Based on the category name and attribute description of the variable attributes of the iOS category, an iOS category declaration configuration code file package is obtained from the set of content code files to be declared. Based on the declaration configuration code file package, a corresponding target macro code file installation package is obtained. The iOS category attributes are added based on the target macro code file installation package. The basic macro code file includes the implementation method of the variable attributes. When the target macro code file installation package is run, the target macro code file in the installation package is first replaced by the first macro code file for object type properties and / or the second macro code file for basic data type properties. Then, the first macro code file for object type properties and / or the second macro code file for basic data type properties are replaced by the preset base macro code file. This macro replacement reduces the amount of code segments, thereby reducing the size of the installation package for iOS projects and facilitating application promotion. In addition, macro replacement reduces the need for manual coding, improving the accuracy of the installation package code and further reducing application crashes caused by missing implementation methods. Furthermore, during the process of adding iOS category attributes, macros are used to perform text replacement on the code during the program preprocessing stage before the source code is compiled, enabling the addition of iOS category attributes using the above methods.
[0173] This application also provides an electronic device, which includes: a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for communication between the processor and the memory. When the program is executed by the processor, it implements the aforementioned method for adding iOS category attributes. This electronic device can be any smart terminal, including tablet computers, in-vehicle computers, etc.
[0174] The electronic device provided in this application first declares iOS category attributes, including category names and attribute descriptions for variable attributes, such as object type attributes and basic data type attributes. Then, it executes macros corresponding to the declared content to add iOS category attributes. The macros corresponding to the declared content are determined based on the names of the variable attributes, the macros for object type attributes, and the macros for basic data type attributes. Both the object type attribute macros and the basic data type attribute macros are determined based on preset base macros, which include the implementation methods for the variable attributes. In other words, base macros are first defined, then the macros for object type attributes and basic data type attributes are determined based on the base macros, then the macros corresponding to the declared content are determined based on the object type attribute macros and the basic data type attribute macros, and finally, the macros corresponding to the declared content are executed to add iOS category attributes. During the iOS category attribute addition process, macros replace text in the code during the program preprocessing stage before source code compilation, reducing manual coding and thus improving the efficiency and accuracy of adding iOS category attributes, further reducing application crashes caused by missing implementation methods.
[0175] Please see Figure 9 , Figure 9 The hardware structure of an electronic device according to another embodiment is illustrated. The electronic device includes:
[0176] The processor 901 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application.
[0177] The memory 902 can be implemented as a read-only memory (ROM), static storage device, dynamic storage device, or random access memory (RAM). The memory 902 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 902 and called and executed by the processor 901 to execute the iOS category attribute addition method of the embodiments of this application.
[0178] The input / output interface 903 is used to implement information input and output;
[0179] The communication interface 904 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).
[0180] Bus 905 transmits information between various components of the device (e.g., processor 901, memory 902, input / output interface 903, and communication interface 904);
[0181] The processor 901, memory 902, input / output interface 903, and communication interface 904 are connected to each other within the device via bus 905.
[0182] This application embodiment also provides a storage medium, which is a computer-readable storage medium for computer-readable storage. The storage medium stores one or more programs, which can be executed by one or more processors to implement the above-described method for adding iOS category attributes.
[0183] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0184] The storage medium provided in this application first declares iOS category attributes, including category names and attribute descriptions for variable attributes, such as object type attributes and basic data type attributes. Then, it executes macros corresponding to the declared content to add iOS category attributes. The macros corresponding to the declared content are determined based on the names of the variable attributes, the macros for object type attributes, and the macros for basic data type attributes. Both the macros for object type attributes and basic data type attributes are determined based on preset base macros, which include the implementation methods for the variable attributes. In other words, base macros are first defined, then the macros for object type attributes and basic data type attributes are determined based on the base macros, then the macros corresponding to the declared content are determined based on the macros for object type attributes and basic data type attributes, and finally, the macros corresponding to the declared content are executed to add iOS category attributes. During the process of adding iOS category attributes, macros replace text in the code during the program preprocessing stage before source code compilation, reducing manual coding and thus improving the efficiency and accuracy of adding iOS category attributes, further reducing application crashes caused by missing implementation methods.
[0185] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0186] It will be understood by those skilled in the art that Figure 1-7 The technical solutions shown do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.
[0187] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0188] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.
[0189] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0190] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0191] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of the units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0192] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0193] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0194] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0195] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.
Claims
1. A method for adding category attributes in iOS, characterized in that, The method includes: Based on the preset basic macro code file, a first macro code file for object type attributes and a second macro code file for basic data type attributes are obtained; the basic macro code file contains the implementation method of variable attributes, the first macro code file for object type attributes includes a macro code file for configuring strong reference attributes and a macro code file for configuring weak reference attributes, and the basic macro code file includes a macro code file for strong reference types and a macro code file for weak reference types; Based on the first macro code file and the second macro code file, determine the set of code files to be declared; Based on the category name and variable attribute description of the iOS category, obtain the declaration configuration code file package of the iOS category from the set of code files to be declared; Based on the declared configuration code file package, obtain the target macro code file installation package corresponding to the category name and the attribute description of the variable attribute; Based on the target macro code file installation package, add the category attributes of the iOS; The attribute description is used to obtain the declaration content file type and the target macro file type. The declaration content file type is used to obtain the declaration configuration code file package, and the target macro file type is used to obtain the target macro code file installation package. The macro code file for configuring strong reference attributes is determined by the following method: defining the strong reference type macro code file, which includes the name of the access method and the caching strategy; and determining the macro code file for configuring strong reference attributes based on the strong reference type macro code file. The macro code file for configuring weak reference attributes is determined by the following method: defining the weak reference type macro code file, which includes the name of the access method; and determining the macro code file for configuring weak reference attributes based on the weak reference type macro code file. During code execution, macros for object type properties or basic data type properties are replaced with their corresponding base macros, and the base macros are replaced with their corresponding code.
2. The method according to claim 1, characterized in that, The basic macro code file includes non-object type macro code files, and the second macro code file for the basic data type attributes is determined by the following method: Define the non-object type macro code file, which includes the names of the access methods and the data type conversion methods; The second macro code file is determined based on the non-object type macro code file to identify the basic data type attributes.
3. The method according to claim 1, characterized in that, The step of obtaining the declaration configuration code file package for the iOS category from the set of code files to be declared, based on the category name and attribute description of the variable attributes of the iOS category, specifically includes: Based on the attribute description of the variable attribute, obtain the corresponding declaration content file type from the set of content files to be declared; The iOS declaration configuration code file is determined based on the file type of the declaration content and the category name of the iOS category; The declaration configuration code file package is obtained based on the declaration configuration code file and the declaration implementation code file.
4. The method according to claim 1, characterized in that, The step of configuring the code file package according to the declaration, and obtaining the target macro code file installation package corresponding to the category name and the attribute description of the variable attribute, specifically includes: Based on the attribute description of the variable attribute, obtain the corresponding target macro file type; Based on the target macro file type and the category name, obtain the target macro code file from the first macro code file and / or the second macro code file; The target macro code file installation package is obtained based on the target macro code file and the macro implementation code file.
5. The method according to claim 1, characterized in that, The category names for the iOS categories are determined using the following method: Determine the category corresponding to the iOS category; The category name of the iOS category is determined based on the name of the class.
6. A device for adding category attributes in iOS, characterized in that, The device includes: The first module is used to obtain a first macro code file for object type attributes and a second macro code file for basic data type attributes based on a preset basic macro code file; the basic macro code file contains the implementation method of variable attributes, the first macro code file for object type attributes includes a macro code file for configuring strong reference attributes and a macro code file for configuring weak reference attributes, and the basic macro code file includes a macro code file for strong reference types and a macro code file for weak reference types. The second module is used to determine the set of code files to be declared based on the first macro code file and the second macro code file; The third module is used to obtain the declaration configuration code file package of the iOS category from the set of code files to be declared based on the category name and attribute description of the variable attributes of the iOS category. The fourth module is used to configure the code file package according to the declaration, and obtain the target macro code file installation package corresponding to the category name and the attribute description of the variable attribute; The fifth module is used to add the category attributes of the iOS based on the target macro code file installation package; The attribute description is used to obtain the declaration content file type and the target macro file type. The declaration content file type is used to obtain the declaration configuration code file package, and the target macro file type is used to obtain the target macro code file installation package. The macro code file for configuring strong reference attributes is determined by the following method: defining the strong reference type macro code file, which includes the name of the access method and the caching strategy; and determining the macro code file for configuring strong reference attributes based on the strong reference type macro code file. The macro code file for configuring weak reference attributes is determined by the following method: defining the weak reference type macro code file, which includes the name of the access method; and determining the macro code file for configuring weak reference attributes based on the weak reference type macro code file. During code execution, macros for object type properties or basic data type properties are replaced with their corresponding base macros, and the base macros are replaced with their corresponding code.
7. An electronic device, characterized in that, The electronic device includes a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for enabling communication between the processor and the memory, wherein the program, when executed by the processor, implements the steps of the method as described in any one of claims 1 to 5.
8. A storage medium, said storage medium being a computer-readable storage medium for computer-readable storage, characterized in that, The storage medium stores one or more programs, which can be executed by one or more processors to implement the steps of the method according to any one of claims 1 to 5.