This column will continue to update – please iOS friends pay attention!
(The answer is not unique, just for reference,)
1. What are the data persistence schemes in iOS?
NSUserDefault
Simple data fast read and writeProperty list
(property list) File storageArchiver
(archive)SQLite
Local databaseCoreData
2. What are serialization and deserialization, and what are they used for
- Serialization – The process of converting an object into a sequence of bytes
- Antisequentialization restores a direct sequence to an object
- Function – Writes objects to a file or database and reads them out
3. Implement complex object storage in OC
- Follow the NSCoding protocol to realize the storage of complex objects. After the implementation of this protocol, it can be packaged or unpackaged and converted into NSDate
How to use SQLite data store?
- Add SQLite dynamic library:
- #import
- Use C language function to create \ open database, write SQL statement
5. What is CoreData?
- CoreData is a framework that emerged after iOS5. It is essentially an encapsulation of SQLite. It provides object-relational mapping (ORM) functions, which can convert OC objects into data, save it in SQLite database files, and restore data stored in the database to OC objects. Managing your application’s data model through CoreData greatly reduces the amount of code you have to write!
6. Describe the client cache mechanism briefly.
- The cache can be classified into memory cache, database cache, and file cache
- Every time I want to get the data
- First check whether there is a cache in the memory
- Check local cache again (database \ files)
- Finally send the network request
- Cache the network data returned by the server (memory, database, file) for the next read
7. What is nS-managed object model?
Ns-managed BJCET is a subclass of NSObject, an important part of Core Date. Ns-managedobjcet is a generic class that implements the basic functionality of the Core Date model layer. Users can build their own data models with NS-ManageDoBjCET.
Say what you know about SQLite
- SQLite is currently the mainstream embedded relational database, its main characteristics are lightweight, cross-platform, many embedded operating systems as the database of choice.
9. Say what you know about FMDB
- FMDB is a third party framework for handling data storage. The framework is a wrapper around SQLite. The framework is lightweight yet flexible and more object-oriented.
- We know that using libsqlite3 directly for database operations is thread unsafe, and unexpected results may occur if multiple threads are working on a table simultaneously. To solve this problem, it is recommended to use the FMDatabaseQueue object in multiple threads, which is thread-safe compared to FMDatabase.
- The reason why transactions are included in FMDB is not because only FMDB supports transactions, but because FMDB encapsulates them into several methods to call without having to write the corresponding SQL. Libsqlite3 supports transactions natively (since transactions are database-based, FMDB is still SQLite), just add “begin transaction;” before executing the SQL statement. After the transaction is complete, run commit Transaction; Or “rollback transaction;” Commit or roll back. In addition, you can also find in Core Data that all add, delete, or change operations must be called after the save method of the context. In fact, the transaction itself supports, as long as the save method is not called, all the previous operations will not be committed. In FMDB, FMDatabase has beginTransaction, commit, and rollback methods to start, commit, and rollback transactions.
10. What is a sandbox mechanic?
- Each iOS application has a separate file system (storage space) and can only operate in the corresponding file system. This area is called the sandbox. Applications must stay in their own sandbox, and other applications cannot access the sandbox.
11. What is the sandbox directory structure?
The sand box structure
-
Documents: common directory, iCloud backup directory, for storing data. Cache files cannot be stored here. Otherwise, the file cannot be put into the shelf
-
Library
- Caches: stores bulky data that does not need to be backed up. This is the SDWebImage cache path
- Preference: Sets the directory. ICloud backs up the Settings
-
TMP: Stores temporary files that will not be backed up, and the data in this file can be deleted at any time
12. How to handle Boolean defaults when using NSUserDefaults? (for example, return NO, whether NO is set or not)
- If you are using
- (void)setBool:(BOOL)value forKey:(NSString *)defaultName;
Method to get the correct bool value - If you are using
- (void)setObject:(nullable id)value forKey:(NSString *)defaultName;
After the value is obtained, convert to bool
13. Code title analysis, what is the print result?
NSUserDefaults *userdefault = [NSUserDefaults standardUserDefaults]; BOOL flag = NO; [userdefault setObject:@(flag) forKey:@"flag"]; if ([userdefault objectForKey:@"flag"]) { BOOL eq = [userdefault objectForKey:@"flag"]; if (eq) { NSLog(@"a"); }else{ NSLog(@"b"); } }else{ BOOL eq = [userdefault objectForKey:@"flag"]; if (eq) { NSLog(@"c"); }else{ NSLog(@"d"); }}Copy the code
A: wrap oc object, oc object has value, bool is yes
11. What if you need to add fields in the database later? What if you don’t use CoreData?
- Write SQL statements to manipulate the fields in the original table
- ALTER TABLE ALTER TABLE name ADD COLUMN Name COLUMN type;
- ALTER TABLE TABLE name DROP COLUMN name;
- ALTER TABLE TABLE name RENAME COLUMN Old COLUMN name TO new COLUMN name;
14.FMDB uses threads and transactions
- FMDatabaseQueue uses this class to ensure thread-safe, serial queues
- A transaction is a basic unit of concurrency control, called a transaction. It is a sequence of operations, all of which are performed or none of which are performed. It is an indivisible unit of work.
15. Differences between XML and JSON
- The advantages of XML format unity, in line with the standard; It is easy to interact with other systems remotely and facilitate data sharing.
- Disadvantages of XML: XML file is large, file format is complex, transmission occupies bandwidth; Parsing XML takes a lot of code on both the server and the client, making the server and client code extremely complex and difficult to maintain. The way XML is parsed from browser to browser on the client is inconsistent, requiring a lot of code duplication; Parsing XML on both the server and client side takes a lot of resources and time.
- The advantages of JSON are: simple data format, easy to read and write, compressed format, low bandwidth; Easy to parse, client-side JavaScript can simply eval() JSON data; Support for a variety of languages, including ActionScript, C, C#, ColdFusion, Java, JavaScript, Perl, PHP, Python, Ruby and other server-side languages, easy server-side parsing;
- The disadvantages of JSON: it is not as popular and widely used as XML format, and it is not as versatile as XML. JSON format is still in its early stage to be popularized in Web Service.
17. What is a business?
- A series of operations performed as a single logical unit of work that requires atomicity, consistency, isolation, and persistence
- Is the basic unit of concurrency control. A transaction is a sequence of operations, all of which are performed or none of which are performed. It is an indivisible unit of work. For example, a bank transfer that takes money from one account and increases money from another account is either done or done nothing. So, think of them as a transaction.
- Transactions are a mechanism for maintaining the integrity of a database
18. Familiar with common SQL statements
create database name drop database name alter table name add column col type select * from table1 where col=value select count as totalcount from table1 select sum(field1) as sumvalue from table1 'insert into table1 (field1,field2) Values (value1,value2) 'delete from table1 where something update table1 set field1=value1 where field1 like' %value1%'Copy the code
Reference: docs.qq.com/doc/DTW1VSU…
19. When a data item in the database is not null, the data obtained through FMDB is
[NSNull null]