菜单

澳门金沙手机客户端ThinkPHP5+Layui完结图片上传加预览

2019年2月13日 - 金沙编程资讯
var uploadInst = upload.render({
      elem:'#cover'
      ,url:'addCourse'
      ,accept:'file'  // 允许上传的文件类型
      ,auto:true // 自动上传
      ,before:function (obj) {
          console.log(obj);
          // 预览
          obj.preview(function(index,file,result) {
              // console.log(file.name);    //图片名字
              // console.log(file.type);    //图片格式
              // console.log(file.size);    //图片大小
              // console.log(result);    //图片地址
              $('#preview').attr('src',result); //图片链接 base64
          });
          // layer.load();
      }
      // 上传成功回调
      ,done:function(res) {
          // console.log(upload);
          console.log(res);

      }
      // 上传失败回调
      ,error:function(index,upload) {
          // 上传失败
      }

  });

野猪

4.5.1 新增、编辑和删除

新增代码组和代码:点击展开树形菜单“系统代码”,可以观望平台置于的一有的代码组和代码。选用“系统代码”后点击“新增分类”按钮,可以加上代码组;拔取已有些代码组,点击“新增代码”按钮,可以添加具体的代码。

在疯长代码组或代码的长河中,其中带大青星号标记“*”的条文,标识、名称和排序ID是必要求填写的始末。平台会检测该代码组或代码的标识、名称在阳台上的合法性,确保代码组或代码的标识、名称的唯一性和可用性。

切切实实添加代码组、代码的操作界面如下图4.5.1-1所示:

 澳门金沙手机客户端 1

 澳门金沙手机客户端 2

图4.5.1-1  新增代码组、代码

private void InfoUpdatedADD()
        {
            if (dmeObj == null)
            {
                lbInfo.Text = "在“系统代码”下新增如下代码分类";
                return;
            }

            if (dmeObj != null && dmeObj is DMESYS_SYSCODE_TYPE)
            {
                dmeCodeType = dmeObj as DMESYS_SYSCODE_TYPE;
                lbInfo.Text = "在代码分类“" + dmeCodeType.Name + "”下新增如下代码";
                return;
            }
        }

        private bool InfoUpdatedEDIT()
        {
            if (dmeObj == null)
            {
                lbInfo.Text = "加载代码类型信息时出错!";
                lbInfo.ForeColor = Color.Red;
                ucCodes.IsEnabled(false);
                return false;
            }

            if (dmeObj != null && dmeObj is DMESYS_SYSCODE_TYPE)
            {
                dmeCodeType = dmeObj as DMESYS_SYSCODE_TYPE;
                lbInfo.Text = "编辑代码分类“" + dmeCodeType.Name + "”";
                return true;
            }

            if (dmeObj != null && dmeObj is DMESYS_SYSCODE)
            {
                dmeCode = dmeObj as DMESYS_SYSCODE;
                lbInfo.Text = "编辑代码“" + dmeCode.Name + "”";
                return true;
            }

            return false;
        }

        private bool InsertorUpdateCodes()
        {
            if (dmeCode == null)
            {
                dmeCode = new DMESYS_SYSCODE();
            }

            if (dmeCodeType == null)
            {
                dmeCodeType = new DMESYS_SYSCODE_TYPE();
            }

            if (action == Action.ADD)
            {
                if (dmeObj == null && DoValidatedCodes())
                {
                    dmeCodeType.Id = FeiQing.DBO.DBOService.GetID();
                    DBOSYS_SYSCODE_TYPE.InsertDMESYS_SYSCODE_TYPE(dmeCodeType);
                    return true;
                }
                if (dmeObj is DMESYS_SYSCODE_TYPE && DoValidatedCodes())
                {
                    dmeCode.Syscode_Type_Id = dmeCodeType.Id;
                    dmeCode.Id = FeiQing.DBO.DBOService.GetID();
                    DBOSYS_SYSCODE.InsertDMESYS_SYSCODE(dmeCode);
                    return true;
                }
                return false;
            }

            if (action == Action.EDIT)
            {
                if (dmeObj is DMESYS_SYSCODE_TYPE && DoValidatedCodes())
                {
                    dmeCodeType.Id = (dmeObj as DMESYS_SYSCODE_TYPE).Id;
                    DBOSYS_SYSCODE_TYPE.UpdateDMESYS_SYSCODE_TYPE(dmeCodeType);
                    return true;
                }
                if (dmeObj is DMESYS_SYSCODE && DoValidatedCodes())
                {
                    dmeCode.Id = (dmeCode as DMESYS_SYSCODE).Id;
                    DBOSYS_SYSCODE.UpdateDMESYS_SYSCODE(dmeCode);
                    return true;
                }
                return false;
            }

            return false;
        }

        private bool DoValidatedCodes()
        {
            if (String.IsNullOrEmpty(ucCodes.LbTxtTag))
            {
                lbTip.Text = "“标识”不能为空。";
                lbTip.ForeColor = Color.Red;
                return false;
            }
            if (String.IsNullOrEmpty(ucCodes.LbTxtName))
            {
                lbTip.Text = "“名称”不能为空。";
                lbTip.ForeColor = Color.Red;
                return false;
            }
            if (String.IsNullOrEmpty(ucCodes.LbTxtOrder))
            {
                lbTip.Text = "“排序ID”不能为空。";
                lbTip.ForeColor = Color.Red;
                return false;
            }
            if (!FeiQing.Util.DataValidator2.IsNumber(ucCodes.LbTxtOrder))
            {
                lbTip.Text = "“排序ID”必须为数值。";
                lbTip.ForeColor = Color.Red;
                return false;
            }

            if (dmeObj == null && dmeCodeType != null && action == Action.ADD)
            {
                dmeCodeType.Tag = ucCodes.LbTxtTag;
                dmeCodeType.Name = ucCodes.LbTxtName;
                dmeCodeType.Order_Id = Int32.Parse(ucCodes.LbTxtOrder);
                dmeCodeType.Remark = ucCodes.LbTxtRemark;
            }
            if (dmeObj is DMESYS_SYSCODE_TYPE && dmeCode != null && action == Action.ADD)
            {
                dmeCode.Tag = ucCodes.LbTxtTag;
                dmeCode.Name = ucCodes.LbTxtName;
                dmeCode.Order_Id = Int32.Parse(ucCodes.LbTxtOrder);
                dmeCode.Remark = ucCodes.LbTxtRemark;
            }
            if (dmeObj is DMESYS_SYSCODE_TYPE && dmeCodeType != null && action == Action.EDIT)
            {
                dmeCodeType.Tag = ucCodes.LbTxtTag;
                dmeCodeType.Name = ucCodes.LbTxtName;
                dmeCodeType.Order_Id = Int32.Parse(ucCodes.LbTxtOrder);
                dmeCodeType.Remark = ucCodes.LbTxtRemark;
            }
            if (dmeObj is DMESYS_SYSCODE && dmeCode != null && action == Action.EDIT)
            {
                dmeCode.Tag = ucCodes.LbTxtTag;
                dmeCode.Name = ucCodes.LbTxtName;
                dmeCode.Order_Id = Int32.Parse(ucCodes.LbTxtOrder);
                dmeCode.Remark = ucCodes.LbTxtRemark;
            }

            return true;
        }

 

编制代码组和代码:主假使在代码组或代码的标识,名称,排序,备注等新闻发生改变的景况时展开的编写操作。点击展开树形菜单“系统代码”,在树型目录下抉择一个代码组只怕代码后点击“编辑”按钮,即成功对应代码组或代码信息的修改。具体编辑代码组、代码的操作界面如下图4.5.1-2中所示:

 澳门金沙手机客户端 3

图4.5.1-2  编辑代码组、代码

 

除去代码组和代码:点击展开树形菜单“系统代码”,在树型目录下抉择一个代码组或代码后点击“删除”按钮,图4.5.1-3体现了除去操作的提醒对话框界面。

备注:对于具有代码的代码组是无能为力直接删除的,首先须求删除其下属的代码。

 澳门金沙手机客户端 4

 澳门金沙手机客户端 5

图4.5.1-3  删除代码组或代码提醒

 

private void btnDelete_Click(object sender, System.EventArgs e)
        {
            if (IsCodeType())
            {
                if (selectedNode.ChildNodes.Count > 0)
                {
                    GUIHelper.MessageToUserInfo("提示:该代码分类包含代码,无法直接删除!");
                    return;
                }
                if (GUIHelper.MessageQuestion("确定要删除代码分类“" + (selectedObj as DMESYS_SYSCODE_TYPE).Name + "”吗?", "删除代码分类"))
                {
                    DBOSYS_SYSCODE_TYPE.DeleteDMESYS_SYSCODE_TYPE(selectedObj as DMESYS_SYSCODE_TYPE);
                    btnRefresh_Click(sender, e);
                    return;
                }
            }
            if (IsCode())
            {
                if (GUIHelper.MessageQuestion("确定要删除代码“" + (selectedObj as DMESYS_SYSCODE).Name + "”吗?", "删除代码"))
                {
                    DBOSYS_SYSCODE.DeleteDMESYS_SYSCODE(selectedObj as DMESYS_SYSCODE);
                    btnRefresh_Click(sender, e);
                    return;
                }
            }
        }

 

php接口

代码 fence_item

objc_copyClassNamesForImage

代码:

unsigned int outCount;
const char **nameList = objc_copyClassNamesForImage("/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.2.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/UIKit.framework/UIKit", &outCount);
for (unsigned i = 0; i < outCount; i++) {
    const char *name = nameList[I];
    NSLog(@"name: %s", name);
}

打印:

部分数据:
TestProject[34509:1304491] name: _UIPreviewPresentationPlatterView
TestProject[34509:1304491] name: UIKeyboardUISettings
TestProject[34509:1304491] name: _UIPickerViewTopFrame
TestProject[34509:1304491] name: _UIOnePartImageView
TestProject[34509:1304491] name: _UIPickerViewSelectionBar
TestProject[34509:1304491] name: _UIPickerWheelView
TestProject[34509:1304491] name: _UIPickerViewTestParameters
TestProject[34509:1304491] name: UIPickerView

4.5 代码(字典)管理

系统代码是阳台置于的、通用的、统一的多少描述。

代码管理(数据字典)是所有平武汉数量描述的实用机制。通过界面进行可视化的操作和维护,能便捷录入和改动平台上统一的字典数据。有效进步了多少的双重利用率和成品、项目标支出功用。整个数据字典数据为框架平台所共享,用户可以更好地对系统举行自定义管理,以满意自身的本性化需求。

代码管理的机能作业区(用户操作)界面如下图4.5-1所示,通过主要的操作按钮和音信内容可见其功能有:

① 新增代码组、代码,编辑代码组、代码,
② 删除代码组、代码,移动代码,
③ 代码组、代码的唯一标识,排序效用和备注新闻等。

个中效用操作按钮的景况会依照拔取的左手树型中不一样节点和见仁见智登录用户的动作权限而改变。

平台在眼下仅扶助二级深度的树型代码结构,可依据实际需求展开添加、修改、删除或挪动等对平台代码进行分类和调动。

澳门金沙手机客户端 6 

图4.5-1  代码管理界面

#region LoadCodeTypes, LoadCodes
        private void LoadCodeTypes(TreeNode currentNode, DMESYS_SYSCODE_TYPE currentCodeType)
        {
            List<DMESYS_SYSCODE_TYPE> subCodeTypes = null;
            if (currentCodeType != null)
                subCodeTypes = DBOSYS_SYSCODE_TYPE.GetSubCodeTypes(currentCodeType);
            else
                subCodeTypes = DBOSYS_SYSCODE_TYPE.GetSYS_SYSCODE_TYPEEntities();

            foreach (DMESYS_SYSCODE_TYPE rt in subCodeTypes)
            {
                TreeNode node = currentNode.ChildNodes.Add();
                node.Tag = rt;
                node.Text = rt.Name;
                node.CollapsedImageIndex = 1;
                node.ExpandedImageIndex = 2;

                LoadCodeTypes(node, rt);
            }
        }

        private void LoadCodes()
        {
            codes.Clear();
            codes = DBOSYS_SYSCODE.GetSYS_SYSCODEEntities();

            foreach (DMESYS_SYSCODE r in codes)
            {
                TreeNode tn = CallFindNode(r.Syscode_Type_Id, tvCodes);
                if (tn != null)
                {
                    TreeNode node = tn.ChildNodes.Add();
                    node.Tag = r;
                    node.Text = r.Name;
                    node.CollapsedImageIndex = 3;
                    node.ExpandedImageIndex = 3;
                }
            }
        }

        private TreeNode FindTreeNode(string codeTypeId, TreeNode tnParent)
        {
            if (tnParent == null || tnParent.Tag is DMESYS_SYSCODE)
                return null;
            if ((tnParent.Tag as DMESYS_SYSCODE_TYPE).Id == codeTypeId)
                return tnParent;
            TreeNode tnRet = null;
            foreach (TreeNode tn in tnParent.ChildNodes)
            {
                tnRet = FindTreeNode(codeTypeId, tn);
                if (tnRet != null)
                    break;
            }
            return tnRet;
        }

        private TreeNode CallFindNode(string codeTypeId, TreeControl treeView)
        {
            TreeNodeCollection nodes = treeView.RootNodes[0].ChildNodes;
            foreach (TreeNode n in nodes)
            {
                TreeNode temp = FindTreeNode(codeTypeId, n);
                if (temp != null)
                    return temp;
            }
            return null;
        }
        #endregion

 

html代码

代码 fossil_piece

object_setIvarWithStrongDefault
/** 
 * Sets the value of an instance variable in an object.
 * 
 * @param obj The object containing the instance variable whose value you want to set.
 * @param ivar The Ivar describing the instance variable whose value you want to set.
 * @param value The new value for the instance variable.
 * 
 * @note Instance variables with known memory management (such as ARC strong and weak)
 *  use that memory management. Instance variables with unknown memory management 
 *  are assigned as if they were strong.
 * @note \c object_setIvar is faster than \c object_setInstanceVariable if the Ivar
 *  for the instance variable is already known.
 */
 // 设置变量中实例变量的值 / iOS 10.0+
OBJC_EXPORT void
object_setIvarWithStrongDefault(id _Nullable obj, Ivar _Nonnull ivar,
                                id _Nullable value) 
    OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);

代码:

Person *p1 = [[Person alloc] init];
Ivar ivar = class_getInstanceVariable([p1 class], "_manTest");
if (@available(iOS 10.0, *)) {
    object_setIvarWithStrongDefault(p1, ivar, @"chen123");
} else {
    // Fallback on earlier versions
}

4.5.2 移动代码

点击展开树形菜单“系统代码”,选取一个代码后点击“移动”按钮,如下图4.5.2-1中所示,选择需求活动到的靶子代码组,点击确认,即可形成代码的调动。目前平台上只协理代码移动,代码组暂时不协理活动。

 澳门金沙手机客户端 7

图4.5.2-1  移动代码

#region LoadCodeTypes
        private void LoadCodeTypes(TreeNode currentNode, DMESYS_SYSCODE_TYPE currentCodeType)
        {
            List<DMESYS_SYSCODE_TYPE> subCodeTypes = null;
            if (currentCodeType != null)
                subCodeTypes = DBOSYS_SYSCODE_TYPE.GetSubCodeTypes(currentCodeType);
            else
                subCodeTypes = DBOSYS_SYSCODE_TYPE.GetSYS_SYSCODE_TYPEEntities();

            foreach (DMESYS_SYSCODE_TYPE rt in subCodeTypes)
            {
                TreeNode node = currentNode.ChildNodes.Add();
                node.Tag = rt;
                node.Text = rt.Name;
                node.CollapsedImageIndex = 1;
                node.ExpandedImageIndex = 2;

                LoadCodeTypes(node, rt);
            }
        }
        #endregion

        private bool MoveCode()
        {
            if (destObj == null)
            {
                lbTip.Visible = true;
                return false;
            }

            if (destObj is DMESYS_SYSCODE_TYPE)
            {
                target.Syscode_Type_Id = (destObj as DMESYS_SYSCODE_TYPE).Id;
                DBOSYS_SYSCODE.UpdateDMESYS_SYSCODE(target);
                return true;
            }

            return false;
        }

 

 

 

主教尾部

object_getIndexedIvars
/** 
 * Returns a pointer to any extra bytes allocated with an instance given object.
 * 
 * @param obj An Objective-C object.
 * 
 * @return A pointer to any extra bytes allocated with \e obj. If \e obj was
 *   not allocated with any extra bytes, then dereferencing the returned pointer is undefined.
 * 
 * @note This function returns a pointer to any extra bytes allocated with the instance
 *  (as specified by \c class_createInstance with extraBytes>0). This memory follows the
 *  object's ordinary ivars, but may not be adjacent to the last ivar.
 * @note The returned pointer is guaranteed to be pointer-size aligned, even if the area following
 *  the object's last ivar is less aligned than that. Alignment greater than pointer-size is never
 *  guaranteed, even if the area following the object's last ivar is more aligned than that.
 * @note In a garbage-collected environment, the memory is scanned conservatively.
 */
// 得到一个
OBJC_EXPORT void * _Nullable object_getIndexedIvars(id _Nullable obj)
    OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0)
    OBJC_ARC_UNAVAILABLE;

澳门金沙手机客户端 8

月之石

SEL

js代码

小鬣犬

class_getMethodImplementation_stret

/** 
 * Returns the function pointer that would be called if a particular 
 * message were sent to an instance of a class.
 * 
 * @param cls The class you want to inspect.
 * @param name A selector.
 * 
 * @return The function pointer that would be called if \c [object name] were called
 *  with an instance of the class, or \c NULL if \e cls is \c Nil.
 */
 // 返回方法的具体的实现
OBJC_EXPORT IMP _Nullable
class_getMethodImplementation_stret(Class _Nullable cls, SEL _Nonnull name) 
    OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0)
    OBJC_ARM64_UNAVAILABLE;

代码:

打印:

<div class="layui-upload">
   <button type="button" class="layui-btn" id="cover">上传封面</button>
</div> 
<div class="layui-input-inline">
   <img id="preview" width="200px" height="200px">
</div>

木门

object_getInstanceVariable
/** 
 * Obtains the value of an instance variable of a class instance.
 * 
 * @param obj A pointer to an instance of a class. Pass the object containing
 *  the instance variable whose value you wish to obtain.
 * @param name A C string. Pass the name of the instance variable whose value you wish to obtain.
 * @param outValue On return, contains a pointer to the value of the instance variable.
 * 
 * @return A pointer to the \c Ivar data structure that defines the type and name of
 *  the instance variable specified by \e name.
 */
 // 获取实例变量的值 MRC 环境下有用
OBJC_EXPORT Ivar _Nullable
object_getInstanceVariable(id _Nullable obj, const char * _Nonnull name,
                           void * _Nullable * _Nullable outValue)
    OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0)
    OBJC_ARC_UNAVAILABLE;

代码:

Person *p1 = [[Person alloc] init];
Ivar ivar = object_getInstanceVariable(p1, "_manTest", nil);
NSLog(@" --- %@", object_getIvar(p1, ivar));

打印:

TestProject[22787:6839305]  --- chen test
 $file = request()->file('file');
 // 移动到框架应用根目录/public/uploads/ 目录下
 $info = $file->move('public/upload/');
 if ($info) {
     $path = 'public/upload/'.$info->getSaveName();
     return return_succ($path);
 }

代码 gargoyle_werepighowl

class_setSuperclass
/** 
 * Sets the superclass of a given class.
 * 
 * @param cls The class whose superclass you want to set.
 * @param newSuper The new superclass for cls.
 * 
 * @return The old superclass for cls.
 * 
 * @warning You should not use this function.
 */
 // 给类设置新的父类
OBJC_EXPORT Class _Nonnull
class_setSuperclass(Class _Nonnull cls, Class _Nonnull newSuper) 
    __OSX_DEPRECATED(10.5, 10.5, "not recommended") 
    __IOS_DEPRECATED(2.0, 2.0, "not recommended") 
    __TVOS_DEPRECATED(9.0, 9.0, "not recommended") 
    __WATCHOS_DEPRECATED(1.0, 1.0, "not recommended")
    __BRIDGEOS_DEPRECATED(2.0, 2.0, "not recommended");

代码:

NSLog(@"%@", class_getSuperclass(NSClassFromString(@"ViewController")));
    class_setSuperclass(NSClassFromString(@"ViewController"), NSClassFromString(@"UIImageView"));
    NSLog(@"%@", class_getSuperclass(NSClassFromString(@"ViewController")));

打印:

TestProject[41901:7839232] UIViewController
TestProject[41901:7839232] UIImageView

4399饔飧不给攻略专区

object_getClassName
/** 
 * Returns the class name of a given object.
 * 
 * @param obj An Objective-C object.
 * 
 * @return The name of the class of which \e obj is an instance.
 */
// 返回这个实例化类的名字
OBJC_EXPORT const char * _Nonnull object_getClassName(id _Nullable obj)
    OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);

代码 chesspiece_knight_marble/stone

objc_allocateClassPair

/* Adding Classes */

/** 
 * Creates a new class and metaclass.
 * 
 * @param superclass The class to use as the new class's superclass, or \c Nil to create a new root class.
 * @param name The string to use as the new class's name. The string will be copied.
 * @param extraBytes The number of bytes to allocate for indexed ivars at the end of 
 *  the class and metaclass objects. This should usually be \c 0.
 * 
 * @return The new class, or Nil if the class could not be created (for example, the desired name is already in use).
 * 
 * @note You can get a pointer to the new metaclass by calling \c object_getClass(newClass).
 * @note To create a new class, start by calling \c objc_allocateClassPair. 
 *  Then set the class's attributes with functions like \c class_addMethod and \c class_addIvar.
 *  When you are done building the class, call \c objc_registerClassPair. The new class is now ready for use.
 * @note Instance methods and instance variables should be added to the class itself. 
 *  Class methods should be added to the metaclass.
 */
功能:创建一个新的类和这个元类
去创建一个新的类开始通过objc_allocateClassPair,然后设置类的属性和功能用class_addMethod和class_addIvar,实例化方法和实例化变量应该被添加到类本身,类应该添加到元类中。
OBJC_EXPORT Class _Nullable
objc_allocateClassPair(Class _Nullable superclass, const char * _Nonnull name, 
                       size_t extraBytes) 
    OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);

代码 minisign_item

objc_getMetaClass
/** 
 * Returns the metaclass definition of a specified class.
 * 
 * @param name The name of the class to look up.
 * 
 * @return The \c Class object for the metaclass of the named class, or \c nil if the class
 *  is not registered with the Objective-C runtime.
 * 
 * @note If the definition for the named class is not registered, this function calls the class handler
 *  callback and then checks a second time to see if the class is registered. However, every class
 *  definition must have a valid metaclass definition, and so the metaclass definition is always returned,
 *  whether it’s valid or not.
 */
 // 得到一个类的元类
OBJC_EXPORT Class _Nullable
objc_getMetaClass(const char * _Nonnull name)
    OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);

代码:

Cat *cat1 = [[Cat alloc] init];
Class c1 = objc_getMetaClass("Cat");
NSLog(@"%@", c1);
NSLog(@"%@", cat1.name);

打印:

TestProject[25712:7077004] Cat
TestProject[25712:7077004] testH

迷你国际象棋

objc_registerProtocol

/** 
 * Registers a newly constructed protocol with the runtime. The protocol
 * will be ready for use and is immutable after this.
 * 
 * @param proto The protocol you want to register.
 */
 // 注册协议
OBJC_EXPORT void
objc_registerProtocol(Protocol * _Nonnull proto) 
    OBJC_AVAILABLE(10.7, 4.3, 9.0, 1.0, 2.0);

代码:

Protocol *protocol = objc_allocateProtocol("PersonDelegate");
// 声明这个协议还是不可以用的,还是要注册这个协议的
objc_registerProtocol(protocol);

打印:

(lldb) po protocol
<Protocol: 0x6080000a84c0>

代码 deer

class_getClassMethod

/** 
 * Returns a pointer to the data structure describing a given class method for a given class.
 * 
 * @param cls A pointer to a class definition. Pass the class that contains the method you want to retrieve.
 * @param name A pointer of type \c SEL. Pass the selector of the method you want to retrieve.
 * 
 * @return A pointer to the \c Method data structure that corresponds to the implementation of the 
 *  selector specified by aSelector for the class specified by aClass, or NULL if the specified 
 *  class or its superclasses do not contain an instance method with the specified selector.
 *
 * @note Note that this function searches superclasses for implementations, 
 *  whereas \c class_copyMethodList does not.
 */
 // 获取类方法
OBJC_EXPORT Method _Nullable
class_getClassMethod(Class _Nullable cls, SEL _Nonnull name)
    OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);

代码:

Method method = class_getClassMethod([Person class], @selector(test));

打印:

(lldb) po method
0x0000000106c633d8

代码 chesspiece_rook_marble/stone

class_copyProtocolList

/** 
 * Describes the protocols adopted by a class.
 * 
 * @param cls The class you want to inspect.
 * @param outCount On return, contains the length of the returned array. 
 *  If outCount is NULL, the length is not returned.
 * 
 * @return An array of pointers of type Protocol* describing the protocols adopted 
 *  by the class. Any protocols adopted by superclasses or other protocols are not included. 
 *  The array contains *outCount pointers followed by a NULL terminator. You must free the array with free().
 * 
 *  If cls adopts no protocols, or cls is Nil, returns NULL and *outCount is 0.
 */
 // 得到一个类遵守协议的个数
OBJC_EXPORT Protocol * __unsafe_unretained _Nonnull * _Nullable 
class_copyProtocolList(Class _Nullable cls, unsigned int * _Nullable outCount)
    OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);

代码:

unsigned int count;
Protocol **protocolList = class_copyProtocolList([UITableViewController class], &count);
for (unsigned int i = 0; i < count; i++) {
    Protocol *pro = protocolList[I];
    NSLog(@"%s", protocol_getName(pro));
}

打印:

TestProject[19640:180921] _UIKeyboardAutoRespondingScrollViewController
TestProject[19640:180921] UITableViewFocusDelegateLegacy
TestProject[19640:180921] UIViewControllerPreviewingDelegate
TestProject[19640:180921] UIViewControllerPreviewingDelegate_Deprecated
TestProject[19640:180921] UITableViewDelegate
TestProject[19640:180921] UITableViewDataSource

代码 moonbase

class_getImageName

/** 
 * Returns the dynamic library name a class originated from.
 * 
 * @param cls The class you are inquiring about.
 * 
 * @return The name of the library containing this class.
 */
 // 返回这个类 源动态库名称
OBJC_EXPORT const char * _Nullable
class_getImageName(Class _Nullable cls) 
    OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);

代码:

const char *libraryName = class_getImageName([UIViewController class]);
NSLog(@"name: %s", libraryName);

打印:

TestProject[34267:1284976] name: /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.2.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/UIKit.framework/UIKit

金丝雀

class_getSuperclass
/** 
 * Returns the superclass of a class.
 * 
 * @param cls A class object.
 * 
 * @return The superclass of the class, or \c Nil if
 *  \e cls is a root class, or \c Nil if \e cls is \c Nil.
 *
 * @note You should usually use \c NSObject's \c superclass method instead of this function.
 */
 // 得到这个类的父类
OBJC_EXPORT Class _Nullable
class_getSuperclass(Class _Nullable cls) 
    OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);

代码:

NSLog(@"%@", class_getSuperclass([self class]));

打印:

TestProject[41571:7797664] UIViewController

大理石乔木

结构

struct objc_class {
    Class _Nonnull isa  OBJC_ISA_AVAILABILITY;

#if !__OBJC2__
    Class _Nullable super_class                              OBJC2_UNAVAILABLE;
    const char * _Nonnull name                               OBJC2_UNAVAILABLE;
    long version                                             OBJC2_UNAVAILABLE;
    long info                                                OBJC2_UNAVAILABLE;
    long instance_size                                       OBJC2_UNAVAILABLE;
    struct objc_ivar_list * _Nullable ivars                  OBJC2_UNAVAILABLE;
    struct objc_method_list * _Nullable * _Nullable methodLists                    OBJC2_UNAVAILABLE;
    struct objc_cache * _Nonnull cache                       OBJC2_UNAVAILABLE;
    struct objc_protocol_list * _Nullable protocols          OBJC2_UNAVAILABLE;
#endif

} OBJC2_UNAVAILABLE;

代码 mushroom_farm

sel_isMapped
/** 
 * Identifies a selector as being valid or invalid.
 * 
 * @param sel The selector you want to identify.
 * 
 * @return YES if selector is valid and has a function implementation, NO otherwise. 
 * 
 * @warning On some platforms, an invalid reference (to invalid memory addresses) can cause
 *  a crash. 
 */
// 判断 SEL 是否存在在 SEL Dictionary
OBJC_EXPORT BOOL sel_isMapped(SEL _Nonnull sel)
    OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);

代码:

SEL sel;
if (sel_isMapped(sel)) {
        NSLog(@"有效");
}

打印:

没有打印

包裹

class_copyMethodList

/** 
 * Describes the instance methods implemented by a class.
 * 
 * @param cls The class you want to inspect.
 * @param outCount On return, contains the length of the returned array. 
 *  If outCount is NULL, the length is not returned.
 * 
 * @return An array of pointers of type Method describing the instance methods 
 *  implemented by the class—any instance methods implemented by superclasses are not included. 
 *  The array contains *outCount pointers followed by a NULL terminator. You must free the array with free().
 * 
 *  If cls implements no instance methods, or cls is Nil, returns NULL and *outCount is 0.
 * 
 * @note To get the class methods of a class, use \c class_copyMethodList(object_getClass(cls), &count).
 * @note To get the implementations of methods that may be implemented by superclasses, 
 *  use \c class_getInstanceMethod or \c class_getClassMethod.
 */
 // 得到类的方法列表
OBJC_EXPORT Method _Nonnull * _Nullable
class_copyMethodList(Class _Nullable cls, unsigned int * _Nullable outCount) 
    OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);

代码:

unsigned int count;
Method *methodList = class_copyMethodList([self class], &count);
for (unsigned int i = 0; i < count; i++) {
    Method method = methodList[I];
    NSLog(@"%s", sel_getName(method_getName(method)));
}

打印:

TestProject[44285:8024690] testFormat
TestProject[44285:8024690] didReceiveMe
TestProject[44285:8024690] viewDidLoad

澳门金沙手机客户端 9

object_isClass
/** 
 * Returns whether an object is a class object.
 * 
 * @param obj An Objective-C object.
 * 
 * @return true if the object is a class or metaclass, false otherwise.
 */
 // 判断是否是一个不为空的类对象
OBJC_EXPORT BOOL
object_isClass(id _Nullable obj)
    OBJC_AVAILABLE(10.10, 8.0, 9.0, 1.0, 2.0);

代码:

BOOL isp1 = object_isClass([p1 class]);
Person * p2;
BOOL isp2 = object_isClass([p2 class]);
NSString * p3 = @"test";
BOOL isp3 = object_isClass([p3 class]);
NSLog(@"%i", isp1);
NSLog(@"%i", isp2);
NSLog(@"%i", isp3);

打印:

TestProject[24619:6998034] 1
TestProject[24619:6998034] 0
TestProject[24619:6998034] 1

代码 shadowheart

定义

/// An opaque type that represents a category.
typedef struct objc_category *Category;

代码 chesspiece_bishop_marble/stone

objc_getClassList
/** 
 * Obtains the list of registered class definitions.
 * 
 * @param buffer An array of \c Class values. On output, each \c Class value points to
 *  one class definition, up to either \e bufferCount or the total number of registered classes,
 *  whichever is less. You can pass \c NULL to obtain the total number of registered class
 *  definitions without actually retrieving any class definitions.
 * @param bufferCount An integer value. Pass the number of pointers for which you have allocated space
 *  in \e buffer. On return, this function fills in only this number of elements. If this number is less
 *  than the number of registered classes, this function returns an arbitrary subset of the registered classes.
 * 
 * @return An integer value indicating the total number of registered classes.
 * 
 * @note The Objective-C runtime library automatically registers all the classes defined in your source code.
 *  You can create class definitions at runtime and register them with the \c objc_addClass function.
 * 
 * @warning You cannot assume that class objects you get from this function are classes that inherit from \c NSObject,
 *  so you cannot safely call any methods on such classes without detecting that the method is implemented first.
 */
 // 获取所有已经注册的类
OBJC_EXPORT int
objc_getClassList(Class _Nonnull * _Nullable buffer, int bufferCount)
    OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);

代码:

Class *bufferClass;
int numClasses;
numClasses = objc_getClassList(NULL, 0);
if(numClasses > 0) {
    bufferClass = (Class *)malloc(sizeof(Class)*numClasses);
    numClasses = objc_getClassList(bufferClass, numClasses);
    NSLog(@"numer of classes: %d", numClasses);
    for (int i = 0; i < numClasses; i++) {
        Class cls = bufferClass[i];
        NSLog(@"class name: %s", class_getName(cls));
    }
    free(bufferClass);
}

出口结果:

TestProject[41171:7767871] numer of classes: 4739

进去游玩后按“~”键调出控制台;

class_getVersion
/** 
 * Returns the version number of a class definition.
 * 
 * @param cls A pointer to a \c Class data structure. Pass
 *  the class definition for which you wish to obtain the version.
 * 
 * @return An integer indicating the version number of the class definition.
 *
 * @see class_setVersion
 */
 // 获取类的版本号  待续...
OBJC_EXPORT int
class_getVersion(Class _Nullable cls)
    OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);

代码:

NSLog(@"%d", class_getVersion([self class]));

打印:

TestProject[42051:7849333] 0

龙鳞火炉

objc_property_t

定义:

/// An opaque type that represents an Objective-C declared property.
typedef struct objc_property *objc_property_t;

迷你主教象棋深藕红/木色

sel_registerName
/** 
 * Registers a method with the Objective-C runtime system, maps the method 
 * name to a selector, and returns the selector value.
 * 
 * @param str A pointer to a C string. Pass the name of the method you wish to register.
 * 
 * @return A pointer of type SEL specifying the selector for the named method.
 * 
 * @note You must register a method name with the Objective-C runtime system to obtain the
 *  method’s selector before you can add the method to a class definition. If the method name
 *  has already been registered, this function simply returns the selector.
 */

// 注册一个方法,对这个runtime系统返回一个SEL,如果这个方法的名字早已经被注册,那么这个函数只会返回 SEL
OBJC_EXPORT SEL _Nonnull sel_registerName(const char * _Nonnull str)
    OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);

代码:

((void (*)(id, SEL))(void *)objc_msgSend)((id)self, sel_registerName("testFormat"));

打印:

TestProject[22427:6817642] testFormat

绘图桌

sel_getUid
/** 
 * Registers a method name with the Objective-C runtime system.
 * 
 * @param str A pointer to a C string. Pass the name of the method you wish to register.
 * 
 * @return A pointer of type SEL specifying the selector for the named method.
 * 
 * @note The implementation of this method is identical to the implementation of \c sel_registerName.
 * @note Prior to OS X version 10.0, this method tried to find the selector mapped to the given name
 *  and returned \c NULL if the selector was not found. This was changed for safety, because it was
 *  observed that many of the callers of this function did not check the return value for \c NULL.
 */
// 向 runtime系统根据字符串注册一个方法,返回SEL
OBJC_EXPORT SEL _Nonnull sel_getUid(const char * _Nonnull str)
    OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);

代码:

((void (*)(id, SEL))(void *)objc_msgSend)((id)self, sel_getUid("testFormat"));

打印:

TestProject[22472:6820361] testFormat

代码 sculpture_rookbody

结构

struct objc_category {
    // 分类名字
    char * _Nonnull category_name                            OBJC2_UNAVAILABLE;
    // 类名
    char * _Nonnull class_name                               OBJC2_UNAVAILABLE;
    // objc 实例方法列表
    struct objc_method_list * _Nullable instance_methods     OBJC2_UNAVAILABLE;
    // objc 类方法列表
    struct objc_method_list * _Nullable class_methods        OBJC2_UNAVAILABLE;
    // 协议列表
    struct objc_protocol_list * _Nullable protocols          OBJC2_UNAVAILABLE;
}                                                            OBJC2_UNAVAILABLE;

代码 chesspiece_pawn_marble/stone

protocol_conformsToProtocol

/** 
 * Returns a Boolean value that indicates whether one protocol conforms to another protocol.
 * 
 * @param proto A protocol.
 * @param other A protocol.
 * 
 * @return \c YES if \e proto conforms to \e other, otherwise \c NO.
 * 
 * @note One protocol can incorporate other protocols using the same syntax 
 *  that classes use to adopt a protocol:
 *  \code
 *  @protocol ProtocolName < protocol list >
 *  \endcode
 *  All the protocols listed between angle brackets are considered part of the ProtocolName protocol.
 */
 // 判断一个协议是否遵从了另外一个协议,第一个协议是否遵守了第二个协议
OBJC_EXPORT BOOL
protocol_conformsToProtocol(Protocol * _Nullable proto,
                            Protocol * _Nullable other)
    OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);

代码:

Protocol *tableViewDelegate = objc_getProtocol("UITableViewDelegate");
Protocol *scrollViewDelegate = objc_getProtocol("UIScrollViewDelegate");
BOOL isConform = protocol_conformsToProtocol(tableViewDelegate, scrollViewDelegate);

打印:

(lldb) po isConform
YES
点进去,可以看到第一个协议确实遵守了第二个协议

代码 sculpture_knighthead

protocol_getName

/** 
 * Returns the name of a protocol.
 * 
 * @param p A protocol.
 * 
 * @return The name of the protocol \e p as a C string.
 */
 根据协议得到协议的名称
OBJC_EXPORT const char * _Nonnull
protocol_getName(Protocol * _Nonnull proto)
    OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);

代码:

Protocol *protocolA = objc_getProtocol("UITableViewDataSource");
NSLog(@"%s", protocol_getName(protocolA));

打印:

TestProject[23900:551699] UITableViewDataSource

澳门金沙手机客户端 10

动态库

代码 sculpture_knighthead

class_getInstanceSize
/** 
 * Returns the size of instances of a class.
 * 
 * @param cls A class object.
 * 
 * @return The size in bytes of instances of the class \e cls, or \c 0 if \e cls is \c Nil.
 */
 // 返回实例类的大小,以字节为单位
OBJC_EXPORT size_t
class_getInstanceSize(Class _Nullable cls) 
    OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);

代码:

NSLog(@"%ld", class_getInstanceSize([self class]));

打印:

TestProject[42305:7873713] 760

代码 sculpture_rooknose

protocol_copyProtocolList

/** 
 * Returns an array of the protocols adopted by a protocol.
 * 
 * @param proto A protocol.
 * @param outCount Upon return, contains the number of elements in the returned array.
 * 
 * @return A C array of protocols adopted by \e proto. The array contains \e *outCount pointers
 *  followed by a \c NULL terminator. You must free the array with \c free().
 *  If the protocol declares no properties, \c NULL is returned and \c *outCount is \c 0.
 */
 // 返回协议所遵守的协议,以数组的形式展现
OBJC_EXPORT Protocol * __unsafe_unretained _Nonnull * _Nullable
protocol_copyProtocolList(Protocol * _Nonnull proto,
                          unsigned int * _Nullable outCount)
    OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);

代码:

Protocol *protocolA = objc_getProtocol("CatDelegate");
unsigned int outCount;
Protocol **protocolList = protocol_copyProtocolList(protocolA, &outCount);
for (unsigned int i = 0; i < outCount; i++) {
    Protocol *protocol = protocolList[I];
    NSLog(@"name --- %s", protocol_getName(protocol));
}

打印:

TestProject[26997:828030] name --- NSObject

无睛鹿

class_getWeakIvarLayout

/** 
 * Returns a description of the layout of weak Ivars for a given class.
 * 
 * @param cls The class to inspect.
 * 
 * @return A description of the layout of the weak \c Ivars for \e cls.
 */
 //  待续
OBJC_EXPORT const uint8_t * _Nullable
class_getWeakIvarLayout(Class _Nullable cls)
    OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);

代码:

打印:

代码 gargoyle_werepigdeath

objc_copyClassList
/** 
 * Creates and returns a list of pointers to all registered class definitions.
 * 
 * @param outCount An integer pointer used to store the number of classes returned by
 *  this function in the list. It can be \c nil.
 * 
 * @return A nil terminated array of classes. It must be freed with \c free().
 * 
 * @see objc_getClassList
 */
 // 获取所有已经注册的类
OBJC_EXPORT Class _Nonnull * _Nullable
objc_copyClassList(unsigned int * _Nullable outCount)
    OBJC_AVAILABLE(10.7, 3.1, 9.0, 1.0, 2.0);

代码:

unsigned int outCount;
Class *classes = objc_copyClassList(&outCount);
for (int i = 0; i < outCount; i++) {
    NSLog(@"%s", class_getName(classes[i]));
}

打印:

TestProject[41322:7782252] JSExport
TestProject[41322:7782252] NSLeafProxy
TestProject[41322:7782252] NSProxy
TestProject[41322:7782252] _UITargetedProxy
TestProject[41322:7782252] _UIViewServiceReplyControlTrampoline

代码 opalpreciousgem

class_getIvarLayout

/** 
 * Returns a description of the \c Ivar layout for a given class.
 * 
 * @param cls The class to inspect.
 * 
 * @return A description of the \c Ivar layout for \e cls.
 */
 // 返回一个类的修饰属性
OBJC_EXPORT const uint8_t * _Nullable
class_getIvarLayout(Class _Nullable cls)
    OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);

代码:

const uint8_t *array_s = class_getIvarLayout([Person class]);

打印:

(lldb) po array_s
"\x01"

代码 bundlewrap

objc_property_attribute_t

结构:

/// Defines a property attribute
typedef struct {
    const char * _Nonnull name;           /**< The name of the attribute */
    const char * _Nonnull value;          /**< The value of the attribute (usually empty) */
} objc_property_attribute_t;

蜜蜂皇后

objc_registerClassPair

/** 
 * Registers a class that was allocated using \c objc_allocateClassPair.
 * 
 * @param cls The class you want to register.
 */
// 注册创建的类
OBJC_EXPORT void
objc_registerClassPair(Class _Nonnull cls) 
    OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);

蜂冠

protocol_getProperty

/** 
 * Returns the specified property of a given protocol.
 * 
 * @param proto A protocol.
 * @param name The name of a property.
 * @param isRequiredProperty \c YES searches for a required property, \c NO searches for an optional property.
 * @param isInstanceProperty \c YES searches for an instance property, \c NO searches for a class property.
 * 
 * @return The property specified by \e name, \e isRequiredProperty, and \e isInstanceProperty for \e proto,
 *  or \c NULL if none of \e proto's properties meets the specification.
 */
 // 根据协议,属性名字返回一个属性
OBJC_EXPORT objc_property_t _Nullable
protocol_getProperty(Protocol * _Nonnull proto,
                     const char * _Nonnull name,
                     BOOL isRequiredProperty, BOOL isInstanceProperty)
    OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);

代码:

Protocol *protocolA = objc_getProtocol("CatDelegate");
objc_property_t pro = protocol_getProperty(protocolA, "testMark", YES, YES);
NSLog(@"%s", property_getName(pro));

打印:

TestProject[25760:731912] testMark

澳门金沙手机客户端 11

class_getInstanceVariable
/** 
 * Returns the \c Ivar for a specified instance variable of a given class.
 * 
 * @param cls The class whose instance variable you wish to obtain.
 * @param name The name of the instance variable definition to obtain.
 * 
 * @return A pointer to an \c Ivar data structure containing information about 
 *  the instance variable specified by \e name.
 */
OBJC_EXPORT Ivar _Nullable
class_getInstanceVariable(Class _Nullable cls, const char * _Nonnull name)
    OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);

代码:

Person *p1 = [[Person alloc] init];
Ivar ivar = class_getInstanceVariable([p1 class], "_manTest");

打印:

(lldb) po ivar
0x00000001098a1460

MOD大全澳门金沙手机客户端 12

/** 
 * Returns the value of a property attribute given the attribute name.
 * 
 * @param property The property whose attribute value you are interested in.
 * @param attributeName C string representing the attribute name.
 *
 * @return The value string of the attribute \e attributeName if it exists in
 *  \e property, \c nil otherwise. 
 */
 // 通过属性的名字得到属性的值
OBJC_EXPORT char * _Nullable
property_copyAttributeValue(objc_property_t _Nonnull property,
                            const char * _Nonnull attributeName)
    OBJC_AVAILABLE(10.7, 4.3, 9.0, 1.0, 2.0);

代码:

id lenderClass = objc_getClass("Person");
unsigned int outCount;
objc_property_t *properties = class_copyPropertyList(lenderClass, &outCount);
for (unsigned int i = 0; i < outCount; i++) {
    objc_property_t property = properties[I];
    fprintf(stdout, "%s %s\n", property_getName(property), property_getAttributes(property));

    unsigned int attrCount = 0;
    objc_property_attribute_t *attrs = property_copyAttributeList(property, &attrCount);
    for (unsigned int j = 0; j < attrCount; j++) {
        objc_property_attribute_t attr = attrs[j];
        const char *name = attr.name;
        const char *value = attr.value;
        const char *test = property_copyAttributeValue(property, name);
        NSLog(@"属性的描述: %s 值: %s", name, value);
        NSLog(@"test -- %s", test);
    }
}

打印:

manTest T@"NSString",&,N,V_manTest
TestProject[23099:496137] 属性的描述: T 值: @"NSString"
TestProject[23099:496137] test -- @"NSString"
TestProject[23099:496137] 属性的描述: & 值: 
TestProject[23099:496137] test -- 
TestProject[23099:496137] 属性的描述: N 值: 
TestProject[23099:496137] test -- 
TestProject[23099:496137] 属性的描述: V 值: _manTest
TestProject[23099:496137] test -- _manTest

age Tq,N,V_age
TestProject[23099:496137] 属性的描述: T 值: q
TestProject[23099:496137] test -- q
TestProject[23099:496137] 属性的描述: N 值: 
TestProject[23099:496137] test -- 
TestProject[23099:496137] 属性的描述: V 值: _age
TestProject[23099:496137] test -- _age

代码 cartographydesk

protocol_addProtocol

/** 
 * Adds an incorporated protocol to another protocol. The protocol being
 * added to must still be under construction, while the additional protocol
 * must be already constructed.
 * 
 * @param proto The protocol you want to add to, it must be under construction.
 * @param addition The protocol you want to incorporate into \e proto, it must be registered.
 */
 // 添加一个已注册的协议到未注册的协议当中
 proto:未注册的协议
 addition:被添加的已注册协议

OBJC_EXPORT void
protocol_addProtocol(Protocol * _Nonnull proto, Protocol * _Nonnull addition) 
    OBJC_AVAILABLE(10.7, 4.3, 9.0, 1.0, 2.0);

代码:

// 声明一个协议返回协议的实例
Protocol *protocol = objc_allocateProtocol("ProjectDelegate");
objc_registerProtocol(protocol);   // 协议方法已经注册

Protocol *testProtocol = objc_allocateProtocol("TestProtocol");
protocol_addProtocol(testProtocol, protocol);

// 打印这个协议遵循的协议组
unsigned int count;
Protocol **protocolList = protocol_copyProtocolList(testProtocol, &count);
for (unsigned int i = 0; i < count; i++) {
    Protocol *protocolC = protocolList[I];
    NSLog(@"name --- %s", protocol_getName(protocolC));
}

打印:

TestProject[32945:1206976] name --- ProjectDelegate

代码 chesspiece_pipe_marble/stone

protocol_isEqual

/** 
 * Returns a Boolean value that indicates whether two protocols are equal.
 * 
 * @param proto A protocol.
 * @param other A protocol.
 * 
 * @return \c YES if \e proto is the same as \e other, otherwise \c NO.
 */
 // 判断两个协议是否相等
OBJC_EXPORT BOOL
protocol_isEqual(Protocol * _Nullable proto, Protocol * _Nullable other)
    OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);

代码:

Protocol *protocolA = objc_getProtocol("UITableViewDataSource");
Protocol *protocolB = NSProtocolFromString(@"UITableViewDataSource");
BOOL isEqual = protocol_isEqual(protocolA, protocolB);

打印:

(lldb) po isEqual
YES

毒蕈树菇

property_getAttributes

/** 
 * Returns the attribute string of a property.
 * 
 * @param property A property.
 *
 * @return A C string containing the property's attributes.
 * 
 * @note The format of the attribute string is described in Declared Properties in Objective-C Runtime Programming Guide.
 */
 // 返回属性的属性字符串
OBJC_EXPORT const char * _Nullable
property_getAttributes(objc_property_t _Nonnull property) 
    OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);

代码:

id lenderClass = objc_getClass("Person");
unsigned int outCount, I;
objc_property_t *properties = class_copyPropertyList(lenderClass, &outCount);
for (unsigned int i = 0; i < outCount; i++) {
    objc_property_t property = properties[I];
    fprintf(stdout, "%s %s\n", property_getName(property), property_getAttributes(property));
}

打印:

manTest T@"NSString",&,N,V_manTest
age Tq,N,V_age

打印解释:

澳门金沙手机客户端 13

image

输入c_give(“代码名称“,数量)物品会按所输多少出现在物品栏;

class_respondsToSelector

/** 
 * Returns a Boolean value that indicates whether instances of a class respond to a particular selector.
 * 
 * @param cls The class you want to inspect.
 * @param sel A selector.
 * 
 * @return \c YES if instances of the class respond to the selector, otherwise \c NO.
 * 
 * @note You should usually use \c NSObject's \c respondsToSelector: or \c instancesRespondToSelector: 
 *  methods instead of this function.
 */
 // 返回一个 Boolean 判断该类是否实现了指定的方法
OBJC_EXPORT BOOL
class_respondsToSelector(Class _Nullable cls, SEL _Nonnull sel) 
    OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);

代码:

BOOL isYES = class_respondsToSelector([self class], @selector(viewWillAppear:));

打印:

(lldb) po isYES
YES

饔飧不继数据库为你提供并日而食物品代码、物品属性介绍、物品的合成和得到方式,快来一起领悟下呢!

ivar_getTypeEncoding
/** 
 * Returns the type string of an instance variable.
 * 
 * @param v The instance variable you want to enquire about.
 * 
 * @return A C string containing the instance variable's type encoding.
 *
 * @note For possible values, see Objective-C Runtime Programming Guide > Type Encodings.
 */
OBJC_EXPORT const char * _Nullable
ivar_getTypeEncoding(Ivar _Nonnull v) 
    OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);

代码:

Person *p1 = [[Person alloc] init];
Ivar ivar = object_getInstanceVariable(p1, "_manTest", nil);
NSLog(@"%s", ivar_getTypeEncoding(ivar));

打印:

TestProject[23004:6857088] @"NSString"

代码 red_mushroomhat

objc_getProtocol

/* Working with Protocols */

/** 
 * Returns a specified protocol.
 * 
 * @param name The name of a protocol.
 * 
 * @return The protocol named \e name, or \c NULL if no protocol named \e name could be found.
 * 
 * @note This function acquires the runtime lock.
 */
 // 获取名称为 name 的协议
OBJC_EXPORT Protocol * _Nullable
objc_getProtocol(const char * _Nonnull name)
    OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);

代码:

Protocol *protocol = objc_getProtocol("UITableViewDataSource");

打印:

(lldb) po protocol
<Protocol: 0x107dbf5e0>

鬣犬

object_getIvar
/** 
 * Reads the value of an instance variable in an object.
 * 
 * @param obj The object containing the instance variable whose value you want to read.
 * @param ivar The Ivar describing the instance variable whose value you want to read.
 * 
 * @return The value of the instance variable specified by \e ivar, or \c nil if \e object is \c nil.
 * 
 * @note \c object_getIvar is faster than \c object_getInstanceVariable if the Ivar
 *  for the instance variable is already known.
 */
1. 读取对象中,实例变量的值
OBJC_EXPORT id _Nullable
object_getIvar(id _Nullable obj, Ivar _Nonnull ivar) 
    OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);

代码:

Person *p1 = [[Person alloc] init];
    Ivar ivar = class_getInstanceVariable([p1 class], "_manTest");
    id mantest = object_getIvar(p1, ivar);
    NSLog(@"%@", mantest);

打印:

TestProject[22563:6825947] chen test

可停放的木门

objc_property_t

代码 bundle

object_copy

/** 
 * Returns a copy of a given object.
 * 
 * @param obj An Objective-C object.
 * @param size The size of the object \e obj.
 * 
 * @return A copy of \e obj.
 */
// 对象的 copy 属于深 copy
OBJC_EXPORT id _Nullable object_copy(id _Nullable obj, size_t size)
    OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0)
    OBJC_ARC_UNAVAILABLE;

代码:

NSLog(@"self --- %p", self);
NSLog(@"object_copy --- %p", object_copy(self, sizeof(self)));

打印:

TestProject[23793:6934176] self --- 0x7f9f8c4049e0
TestProject[23793:6934176] object_copy --- 0x7f9f8c70a1d0

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图