利用 FastCoding 将对象进行本地持久化

2024-09-05 13:48

本文主要是介绍利用 FastCoding 将对象进行本地持久化,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

FastCoding

https://github.com/nicklockwood/FastCoding

A faster and more flexible binary file format replacement for NSCoding, Property Lists and JSON

一个用来替换 NSCoding , Property Lists 以及 JSON 方案的,快速灵活性强的二进制文件存储格式.

Purpose

FastCoder is a high-performance binary serialization format for Cocoa objects and object graphs. It is intended as a replacement for NSPropertyList, NSJSONSerializer, NSKeyedArchiver/Unarchiver and Core Data.

FastCoder 是一个高效的二进制序列化格式,用于存储 Cocoa 对象的.它被设计用来替换 NSPropertyList, NSJSONSerializer, NSKeyedArchiver/Unarchiver 以及 Core Data.

The design goals of the FastCoder library are to be fast, flexible and secure.

FastCoder 库的设计宗旨就是快,高灵活性以及安全.

FastCoder is already faster (on average) for reading than any of the built-in serialization mechanisms in Cocoa, and is faster for writing than any mechanism except for JSON (which doesn't support arbitrary object types). File size is smaller than NSKeyedArchiver, and comparable to the other methods.

FastCoder 在平均水平上读取快过任何 Cocoa 的内置的序列化方案,在写数据方面除了比 JSON (它不支持任意对象类型)慢以外,完爆其它内置的方案.而且,文件大小比 NSKeyedArchiver 小,使用方法却非常简单.

FastCoder supports more data types than either JSON or Plist coding (including NSURL, NSValue, NSSet and NSOrderedSet), and allows all supported object types to be used as the keys in a dictionary, not just strings.

FastCoder 支持的数据类型比 JSON 或者 Plist 编码(其包含了 NSURL, NSValue, NSSet 和 NSOrderedSet )更多的格式,它允许所支持格式的对象像使用键值对那样简单.

FastCoder can also serialize your custom classes automatically using property inspection. For cases where this doesn't work automatically, you can easily implement your own serialization using the FastCoding Protocol.

FastCoder 能够自动序列化你自定义的的类,通过检查你属性的方式.某些情况下无法自动工作时,你可以用 FastCoding 协议简单的实现你自己的序列化方案.

Supported OS & SDK Versions

  • Supported build target - iOS 7.0 / Mac OS 10.9 (Xcode 5.0, Apple LLVM compiler 5.0)
  • Earliest supported deployment target - iOS 5.0 / Mac OS 10.7
  • Earliest compatible deployment target - iOS 4.0 / Mac OS 10.6

NOTE: 'Supported' means that the library has been tested with this version. 'Compatible' means that the library should work on this OS version (i.e. it doesn't rely on any unavailable SDK features) but is no longer being tested for compatibility and may require tweaking or bug fixes to run correctly.

注意:'支持'意味着这个库在那个版本上测试过.'兼容'意味着这个库可以在那个OS版本上工作(i.e. 它不依赖于任何被弃用的 SDK 特性),但是,后续出现bug不再被维护.

ARC Compatibility

FastCoder is compatible with both ARC and non-ARC compile targets, however performance is better when running with ARC disabled, and it is recommended that you apply the -fno-objc-arc compiler flag to the FastCoder.m class. To do this, go to the Build Phases tab in your target settings, open the Compile Sources group, double-click FastCoder.m in the list and type -fno-objc-arc into the popover.

FastCoder 支持 ARC 以及 MRC 编译.在 MRC 下表现得好些.我建议你对 FastCoder.m 文件使用 -fno-objc-arc 编译标签.

Thread Safety

It is safe to call the FastCoder encoding and decoding method concurrently from multiple threads. It should be safe to encode the same object concurrently on multiple threads provided that you do not mutate the object while it is being encoded.

在不同的线程里并发的调用编码和解码的方法是安全的.

 

The chunk types supported by FastCoding are:

FCTypeNull                  an NSNull value
FCTypeAlias                 an alias to an previously encoded chunk in the file
FCTypeString                an NSString instance
FCTypeDictionary            an NSDictionary instance
FCTypeArray                 an NSArray instance
FCTypeSet                   an NSSet instance
FCTypeOrderedSet            an NSOrderedSet instance
FCTypeTrue                  a boolean YES value
FCTypeFalse                 a boolean NO value
FCTypeInt32                 a 32-bit integer value
FCTypeInt64                 a 64-bit integer value
FCTypeFloat32               a 32-bit floating point value
FCTypeFloat64               a 64-bit floating point value
FCTypeData                  an NSData instance
FCTypeDate                  an NSDate instance
FCTypeMutableString         an NSMutableString instance
FCTypeMutableDictionary     an NSMutableDictionary instance
FCTypeMutableArray          an NSMutableArray instance
FCTypeMutableSet            an NSMutableSet instance
FCTypeMutableOrderedSet     an NSMutableOrderedSet instance
FCTypeMutableData           an NSMutableData instance
FCTypeClassDefinition       a class definition (this is a private, internal object type used for object encoding)
FCTypeObject                an arbitrary object, encoded using the FastCoding protocol
FCTypeNil                   a nil value (not the same as NSNull), used for nil object properties
FCTypeURL                   an NSURL value
FCTypePoint                 an NSPoint/CGPoint value
FCTypeSize                  an NSSize/CGSize value
FCTypeRect                  an NSRect/CGRect value
FCTypeRange                 an NSRange value
FCTypeAffineTransform       a CGAffineTransform value
FCType3DTransform           a CATransform3D value

 

附上本人的测试心得:

先打上标签

在定义一个Model,包括了字典,数组,NSDate以及NSString,还有NSInteger.

写如下代码测试

查看打印信息

完美!

 

再测试个高级的,新建 SonModel 继承至 Model

验证代码

打印结果

 

这篇关于利用 FastCoding 将对象进行本地持久化的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1139135

相关文章

SpringMVC高效获取JavaBean对象指南

《SpringMVC高效获取JavaBean对象指南》SpringMVC通过数据绑定自动将请求参数映射到JavaBean,支持表单、URL及JSON数据,需用@ModelAttribute、@Requ... 目录Spring MVC 获取 JavaBean 对象指南核心机制:数据绑定实现步骤1. 定义 Ja

Python打印对象所有属性和值的方法小结

《Python打印对象所有属性和值的方法小结》在Python开发过程中,调试代码时经常需要查看对象的当前状态,也就是对象的所有属性和对应的值,然而,Python并没有像PHP的print_r那样直接提... 目录python中打印对象所有属性和值的方法实现步骤1. 使用vars()和pprint()2. 使

Java使用HttpClient实现图片下载与本地保存功能

《Java使用HttpClient实现图片下载与本地保存功能》在当今数字化时代,网络资源的获取与处理已成为软件开发中的常见需求,其中,图片作为网络上最常见的资源之一,其下载与保存功能在许多应用场景中都... 目录引言一、Apache HttpClient简介二、技术栈与环境准备三、实现图片下载与保存功能1.

MySQL JSON 查询中的对象与数组技巧及查询示例

《MySQLJSON查询中的对象与数组技巧及查询示例》MySQL中JSON对象和JSON数组查询的详细介绍及带有WHERE条件的查询示例,本文给大家介绍的非常详细,mysqljson查询示例相关知... 目录jsON 对象查询1. JSON_CONTAINS2. JSON_EXTRACT3. JSON_TA

C#之List集合去重复对象的实现方法

《C#之List集合去重复对象的实现方法》:本文主要介绍C#之List集合去重复对象的实现方法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录C# List集合去重复对象方法1、测试数据2、测试数据3、知识点补充总结C# List集合去重复对象方法1、测试数据

Linux使用scp进行远程目录文件复制的详细步骤和示例

《Linux使用scp进行远程目录文件复制的详细步骤和示例》在Linux系统中,scp(安全复制协议)是一个使用SSH(安全外壳协议)进行文件和目录安全传输的命令,它允许在远程主机之间复制文件和目录,... 目录1. 什么是scp?2. 语法3. 示例示例 1: 复制本地目录到远程主机示例 2: 复制远程主

Spring中管理bean对象的方式(专业级说明)

《Spring中管理bean对象的方式(专业级说明)》在Spring框架中,Bean的管理是核心功能,主要通过IoC(控制反转)容器实现,下面给大家介绍Spring中管理bean对象的方式,感兴趣的朋... 目录1.Bean的声明与注册1.1 基于XML配置1.2 基于注解(主流方式)1.3 基于Java

C++/类与对象/默认成员函数@构造函数的用法

《C++/类与对象/默认成员函数@构造函数的用法》:本文主要介绍C++/类与对象/默认成员函数@构造函数的用法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录名词概念默认成员函数构造函数概念函数特征显示构造函数隐式构造函数总结名词概念默认构造函数:不用传参就可以

C++类和对象之默认成员函数的使用解读

《C++类和对象之默认成员函数的使用解读》:本文主要介绍C++类和对象之默认成员函数的使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、默认成员函数有哪些二、各默认成员函数详解默认构造函数析构函数拷贝构造函数拷贝赋值运算符三、默认成员函数的注意事项总结一

windows系统上如何进行maven安装和配置方式

《windows系统上如何进行maven安装和配置方式》:本文主要介绍windows系统上如何进行maven安装和配置方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不... 目录1. Maven 简介2. maven的下载与安装2.1 下载 Maven2.2 Maven安装2.