A method for realizing fast storage of iOS native client data
By combining storage utility classes and data model conversion tools from FMDB and MJExtension, the data storage operations on the iOS local client are simplified, solving the problems of complex operations and high error rates in existing technologies, and achieving efficient data management and storage.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-26
- Publication Date
- 2026-04-07
AI Technical Summary
Existing technologies cannot effectively solve the problems that existing technologies cannot solve in data processing.
By combining storage utility classes based on FMDB and MJExtension with the data model transformation tool of MJExtension, a brand-new storage method is generated. Database operations are completed through the model object itself, simplifying data storage operation steps and improving development efficiency.
It simplifies data storage operations, improves development efficiency, reduces the probability of errors, and enhances the availability of data storage.
Smart Images

Figure CN116010440B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application relates to the technical field of mobile phone application product research and development, and particularly relates to a method for realizing rapid storage of iOS local client data. BACKGROUND
[0002] Mobile phone software mainly refers to software installed on a smart phone to improve the shortcomings of an original system and individualization, perfect mobile phone functions and provide a main means for users to have a richer use experience; with the popularization of smart phones, people are increasingly dependent on mobile phone App software in communication, socialization and entertainment activities, wherein App is an abbreviation of Application, that is, application software, usually refers to mobile phone application software such as iphone and Android, mobile phone software is generated by analysis, design, coding and software, and the mobile phone software is a special software.
[0003] With the development of almost all app applications, local caching such as picture caching, data caching and video caching is inevitably used, and video and picture mainly increase file writing and reading operations compared with data caching, and the main research object of this time is data caching.
[0004] Apple itself provides a storage mode of CoreData database, but in actual application, because of the limitations of operation and the inconvenience of modifying the data structure, the applicant has also contacted the pure sql database of FMDBsqlite3, and there are also some problems, because the pure sql of FMDBsqlite3 needs to be manually written, it is easy to write errors, and it is not easy to find the error position. SUMMARY
[0005] The technical problem solved by the application is that:
[0006] In view of the deficiencies in the prior art, the application provides a method for realizing rapid storage of iOS local client data, which can better help developers to manage and use a series of operations related to local storage, that is, one line of code can complete adding, deleting, modifying and inquiring, greatly improves the development efficiency, and solves the technical problems mentioned in the background art.
[0007] Technical scheme:
[0008] To achieve the above purpose, the application is designed based on the combination of FMDB (a pure sql storage tool class) and MJExtension (a data model conversion tool) to generate a new storage method, and the application is realized through the following technical scheme:
[0009] A method for realizing rapid storage of iOS local client data, comprising the following specific operation steps:
[0010] S1. Generation of the debugging tool interface;
[0011] S2, Debugging tool method binding;
[0012] In S2, the model object itself is used to complete database operations, performing CRUD operations on the code. MJExtension is used to obtain all the key and value of the model, and the SQL is reconstructed into a new insert SQL statement and written to the database. Specifically, the method of this application can improve usability: local caching can be achieved by only inheriting the storage base class, and localized operations can be performed by only operating the model. The operation is more efficient: the simplified operation steps reduce the time wasted due to tedious operations such as writing SQL, and avoid errors in the operation steps.
[0013] In one possible implementation, S1 uses the Xcode development tool, integrates a third-party library for FMDB data storage and a third-party library for MJExtension dictionary model conversion into the project, and the project compiles successfully after completion.
[0014] In one possible implementation, debugging tool method binding can be achieved by mastering and implementing local storage through the following steps:
[0015] (1) Use FMDB to create a master table for the database in the sandbox;
[0016] (2) Encapsulate the method for creating a database table, that is, you can create a data table by passing in the table name and an array of table field information;
[0017] The table fields are of the default TEXT type;
[0018] The created data table will have a built-in ID field;
[0019] (3) Encapsulate and implement the use of MJExtension to convert the model object into a dictionary object, and then use a for loop to traverse the keys to get all the key values, and combine this with step (2) to create the database;
[0020] (4) When writing data to the database, another method is encapsulated, that is, only the model object is passed in, and all the key and value of the model are obtained by using MJExtension, and then the SQL is reconstructed into a new insert SQL statement and written to the database.
[0021] (5) Combining the above steps, only one method of inputting the model is exposed in the end, which can realize the storage of local data;
[0022] When implementing local data storage, check if the table exists;
[0023] If it does not exist, then create it;
[0024] If it exists, retrieve the content in the table by model ID; when retrieving the content in the table by model ID, if the content exists in the table, modify the content; if it does not exist, add the content.
[0025] (6) Local database queries also use the model to query, that is, query all the data in the table corresponding to the model. When the query results are found, the result data is converted into a model using MJExtension and returned.
[0026] Among them, queries in the local database support queries that only require an SQL statement.
[0027] (7) When performing a deletion operation, the same method is used: pass in the model object, get the object's ID value, query the database table, and if it exists, delete it.
[0028] (8) Obtain the methods for adding, deleting, modifying and differencing, and generate the base class for method calls. When a model object that needs to be stored locally is required, simply inherit this base class to implement the storage operation of the data object.
[0029] Beneficial effects:
[0030] This application represents a new solution formed by integrating and improving existing technologies:
[0031] First, the method used in this application can improve usability:
[0032] Local caching can be achieved simply by inheriting this storage base class, and localized operations can be performed simply by manipulating the model.
[0033] Secondly, the operation is more efficient:
[0034] The simplified operation steps reduce the time wasted on tedious operations such as writing SQL, and avoid errors in the operation steps. Attached Figure Description
[0035] The above description is merely an overview of the technical solution of the present invention. In order to better understand the technical means of the present invention and to implement it in accordance with the contents of the specification, the preferred embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0036] Figure 1 This is a schematic diagram illustrating the overall design concept of the present invention. Detailed Implementation
[0037] This application provides a method for fast storage of local client data in iOS. This method helps developers better manage and use local storage-related operations, enabling CRUD operations to be completed with a single line of code, greatly improving development efficiency and solving the technical problems mentioned in the background. Its purpose is to help more developers better manage local storage, provide a better data operation experience, save development time, and make local data clearer and more transparent. Simultaneously, the method improves usability: local caching can be implemented simply by inheriting the storage base class, and localized operations can be performed simply by operating the model. Operations are more efficient: simplified operation steps reduce time wasted on tedious operations such as writing SQL, and avoid errors in operation steps.
[0038] The technical solution in this application embodiment is to solve the problems mentioned in the background art, and the overall idea is as follows:
[0039] Example 1:
[0040] This embodiment describes the specific steps of a method for quickly storing local data on an iOS client, such as... Figure 1 As shown, a method for fast storage of local client data on iOS includes the following specific steps (Note: This application design is based on the combination of FMDB <pure SQL storage utility class> and MJExtension <data model conversion tool> to generate a brand new storage method):
[0041] S1. Generation of the debugging tool interface;
[0042] S2, Debugging tool method binding;
[0043] In S2, the model object itself is used to complete database operations, performing CRUD operations on the code. MJExtension is used to obtain all the key and value of the model, which are then reassembled into a new insert SQL statement and written to the database.
[0044] In some examples, S1 uses the Xcode development tool, integrates a third-party library for FMDB data storage and a third-party library for MJExtension dictionary model conversion into the project, and the project compiles successfully after completion.
[0045] In some examples, debugging tool method binding can be implemented and local storage can be mastered through the following steps:
[0046] (1) Use FMDB to create a master table for the database in the sandbox;
[0047] (2) Encapsulate the method for creating a database table, that is, you can create a data table by passing in the table name and an array of table field information;
[0048] The table fields are of the default TEXT type;
[0049] The created data table will have a built-in ID field;
[0050] (3) Encapsulate and implement the use of MJExtension to convert the model object into a dictionary object, and then use a for loop to traverse the keys to get all the key values, and combine this with step (2) to create the database;
[0051] (4) When writing data to the database, another method is encapsulated, that is, only the model object is passed in, and all the key and value of the model are obtained by using MJExtension, and then the SQL is reconstructed into a new insert SQL statement and written to the database.
[0052] (5) Combining the above steps, only one method of inputting the model is exposed in the end, which can realize the storage of local data;
[0053] When implementing local data storage, check if the table exists;
[0054] If it does not exist, then create it;
[0055] If it exists, retrieve the content in the table by model ID; when retrieving the content in the table by model ID, if the content exists in the table, modify the content; if it does not exist, add the content.
[0056] (6) Local database queries also use the model to query, that is, query all the data in the table corresponding to the model. When the query results are found, the result data is converted into a model using MJExtension and returned.
[0057] Among them, queries in the local database support only passing in the SQL statement, such as 'select name for tablename where age=20'.
[0058] (7) When performing a deletion operation, the same method is used: pass in the model object, get the object's ID value, query the database table, and if it exists, delete it.
[0059] (8) Obtain the methods for adding, deleting, modifying and differencing, and generate the base class for method calls. When a model object that needs to be stored locally is required, simply inherit this base class to implement the storage operation of the data object.
[0060] By adopting the above technical solution:
[0061] This application is relative to the prior art;
[0062] First, usability is improved: local caching can be achieved simply by inheriting this storage base class, and localized operations can be performed simply by operating the model.
[0063] Secondly, the operation is more efficient: the simplified operation steps reduce the time wasted due to tedious operations such as writing SQL, and avoid errors in the operation steps.
[0064] This application uses a method that completes database operations by using the model object itself, that is, the localization of the model data can be completed by only operating the model object (here the model can be any object).
[0065] In practical application:
[0066] First, use FMDB to create a master database table in the Apple sandbox; encapsulate a method to create the database table, which simply takes the table name and an array of table fields (default TEXT type) as input to create the data table <built-in ID field>; encapsulate a method to use MJExtension to convert the model object into a dictionary object, then iterate through the keys using a for loop to get all the key values, and combine this with step 2 to create the database; when writing data to the database, encapsulate another method—that is, only take the model object as input, use MJExtension to get all the key and value of the model, and reconstruct it into a new insert SQL statement according to SQL syntax rules, and then write it to the database;
[0067] Secondly, by combining the above steps, only one method for passing in the model needs to be exposed to achieve local data storage; the implementation details are as follows: check if the table exists, if it does not exist, create it, if it exists, retrieve the content in the table by model ID, modify the content if the content exists in the table, and add the content if it does not exist.
[0068] Next is the query of the local database, which also uses the model to perform the query, that is, to query all the data in the table corresponding to the model. It also supports queries that only pass in the SQL statement, such as 'select name for tablename where age=20'. When the query results are found, the result data is converted into a model using MJExtension and returned.
[0069] Finally, when performing a deletion operation, the same model object is passed in, the object's ID value is obtained, and a query is performed in the database table. If it exists, it is deleted. Ultimately, the methods for adding, deleting, modifying, and changing data are exposed, and a base class for method calls is generated. When a model object stored locally is needed, it only needs to inherit from this base class to quickly implement some storage operations for the data object.
[0070] Finally, it should be noted that the above embodiments are merely examples for clearly illustrating the present invention and are not intended to limit the implementation. Those skilled in the art will recognize that other variations or modifications can be made based on the above description. It is neither necessary nor possible to exhaustively list all possible implementations. However, obvious variations or modifications derived therefrom are still within the scope of protection of this invention.
Claims
1. A method for fast storage of local client data in iOS, characterized in that, The specific operational steps are as follows: S1. Generation of the debugging tool interface; S2, Debugging tool method binding; In S2, the model object itself is used to complete database operations, performing CRUD operations on the code. MJExtension is used to obtain all the key and value of the model, and the SQL is reconstructed into a new insert SQL statement and written to the database. In S1, using the Xcode development tool, the project integrates the third-party library for FMDB data storage and the third-party library for MJExtension dictionary model conversion. Once completed, the project compiles successfully. In S2, the debugging tool method binding can be mastered and implemented through the following steps, the specific steps of which are as follows: (1) Use FMDB to create a master database table in the sandbox; (2) Encapsulate the method for creating a database table, that is, you can create a data table by passing in the table name and an array of table field information; (3) Encapsulate and implement the use of MJExtension to convert the model object into a dictionary object, and then use a for loop to traverse the keys to get all the key values, and combine this with step (2) to create the database; (4) When writing data to the database, another method is encapsulated, that is, only the model object is passed in, and all the key and value of the model are obtained by using MJExtension, and then the SQL is reconstructed into a new insert SQL statement and written to the database. (5) By combining the above steps, only one method is exposed for inputting the model, which can achieve local data storage; (6) The local database query also uses the model to query, that is, to query all the data in the table corresponding to the model. When the query results are found, the result data is converted into a model using MJExtension and returned. (7) When performing a deletion operation, the same method is used: pass in the model object, get the object's ID value, query the database table, and if it exists, delete it. (8) Obtain the add, delete, modify and differ methods, generate the base class for method calls, and when a model object in local storage needs to be used, simply inherit this base class to implement the storage operation of the local storage model object.
2. The method for fast storage of local client data in iOS as described in claim 1, characterized in that: In step (2), the table field is of the default TEXT type.
3. The method for fast storage of local client data in iOS as described in claim 1, characterized in that: In step (2), the built-in ID field is created in the resulting data table.
4. The method for fast storage of local client data in iOS as described in claim 1, characterized in that: In step (5), when storing local data, it is determined whether the table exists; If it does not exist, then create it; If it exists, retrieve the content from the table using the model ID.
5. The method for fast storage of local client data in iOS as described in claim 4, characterized in that: When retrieving content from the table by model ID, if the content exists in the table, the content is modified; otherwise, the content is added.
6. The method for fast storage of local client data in iOS as described in claim 1, characterized in that: In step (6), the local database query supports queries that only pass in the SQL statement.