Latest 1.1.1
Homepage https://github.com/ToBeDefined/TPreventKVC
License MIT
Platforms ios 3.1, osx 10.6, tvos 9.0, watchos 1.0, requires ARC
Frameworks Foundation
Authors

TPreventKVC
——

![platform](https://img.shields.io/badge/Platform-iOS%20%7C%20tvOS%20%7C%20macOS%20%7C%20watchOS-brightgreen.svg) 
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) 
[![CocoaPods](https://img.shields.io/badge/Cocoapods-compatible-brightgreen.svg?style=flat)](http://cocoapods.org/) 
[![Build Status](https://travis-ci.org/ToBeDefined/TPreventKVC.svg?branch=master)](https://travis-ci.org/ToBeDefined/TPreventKVC) 
[![License MIT](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/tobedefined/TPreventKVC/blob/master/LICENSE)

[中文文档](README_CN.md)

[How to use TPreventKVC and TPreventKVC’s Principle](http://tbd.ink/2018/04/04/iOS/18040401.TPreventKVC%E7%9A%84%E4%BD%BF%E7%94%A8%E5%92%8C%E5%AE%9E%E7%8E%B0/index/)

Features

Use the runtime dynamic replacement method to prevent NSUnknownKeyException & NSInvalidArgumentException errors from crashing when using KVC’s methods.

  • -valueForKey:
  • setValue:forKey:
  • -setValue:forKeyPath:
  • -valueForKeyPath:, etc.

Installation

Source File

Drag all the files inside the TPreventKVC folder in the corresponding module directory into you project.

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate TPreventKVC into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'TPreventKVC'

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate TPreventKVC into your Xcode project using Carthage, specify it in your Cartfile:

github "tobedefined/TPreventKVC"

Run carthage update to build the framework and drag the built TPreventKVC.framework into your Xcode project.

How to use

After importing the project.

Set Block Get Error Infomation

In the main() function of the APP’s main.m file or in the APP’s didFinishLaunching method add the following code to get the specific information about the missing method:

[NSObject setHandleKVCErrorBlock:^(__unsafe_unretained Class cls, NSString *key, KVCErrorType errorType) {
    // DO SOMETHING
    // like upload to server or print log or others
}];
一些定义

The following definitions and methods are in NSObject+PreventKVC.h

typedef NS_ENUM(NSUInteger, KVCErrorType) {
    KVCErrorTypeSetValueForUndefinedKey     = 1,
    KVCErrorTypeValueForUndefinedKey        = 2,
    KVCErrorTypeSetNilValueForKey           = 3,
};

typedef void (^ __nullable HandleKVCErrorBlock)(Class cls, NSString *key, KVCErrorType errorType);
  • cls: Class type; use NSStringFromClass(cls) to return a class name string for a Class that produces the wrong class or object
  • key: NSString * type; the key to generate the error
  • errorType: KVCErrorType; the type that generated the error
  • callStackSymbols: NSArray<NSString *> * type; call stack infomations

Latest podspec

{
    "name": "TPreventKVC",
    "version": "1.1.1",
    "summary": "Use TPreventKVC can prevent KVC's Exceptions crash, like NSUnknownKeyException & NSInvalidArgumentException",
    "description": "Use TPreventKVC can make you project protect the n`-valueForKey:`n`setValue:forKey:`n`-setValue:forKeyPath:`n`-valueForKeyPath:` and so onnnTo prevent to produce NSUnknownKeyException & NSInvalidArgumentException and crash.ngithub : https://github.com/ToBeDefined/TPreventKVC",
    "homepage": "https://github.com/ToBeDefined/TPreventKVC",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "ToBeDefined": "[email protected]"
    },
    "social_media_url": "http://tbd.ink/",
    "source": {
        "git": "https://github.com/ToBeDefined/TPreventKVC.git",
        "tag": "1.1.1"
    },
    "frameworks": "Foundation",
    "requires_arc": true,
    "platforms": {
        "ios": "3.1",
        "osx": "10.6",
        "tvos": "9.0",
        "watchos": "1.0"
    },
    "public_header_files": "TPreventKVC/*.h",
    "source_files": "TPreventKVC/*.{h,m}"
}

Pin It on Pinterest

Share This