iOS runtime

ops/2024/10/18 19:28:23/

—参考文章—

  • 暂时没有

一、如何在Xcode中使用runtime

Xcode默认是不建议开发者使用runtime的,所以在Xcode直接使用runtime的语法是会报错误的。
如果要在Xcode中使用runtime的语法,是需要配置一下才可以使用,配置方法如下图:

  • 首先在1的位置搜索Enable strict
  • 默认是选中Yes的,然后只要选中No即可,然后在项目中使用runtime语法就不会报错误了

配置runtime使用开关

二、几个常用的语法

  • 获取当前对象的所有方法
/* 获取对象的所有方法 */
-(NSArray *)getAllMethods
{NSMutableArray *tempMuArr = [[NSMutableArray alloc] init];unsigned int methCount = 0;Method *meths = class_copyMethodList([self class], &methCount);for(int i = 0; i < methCount; i++) {Method meth = meths[i];SEL sel = method_getName(meth);const char *name = sel_getName(sel);NSLog(@"%s", name);[tempMuArr addObject:[NSString stringWithFormat:@"%s", name]];}free(meths);return [tempMuArr copy];
}
  • 获取当前对象的所有属性
/* 获取对象的所有属性 */
- (NSArray *)getAllProperties
{u_int count;objc_property_t *properties  = class_copyPropertyList([self class], &count);NSMutableArray *propertiesArray = [NSMutableArray arrayWithCapacity:count];for (int i = 0; i < count ; i++){const char* propertyName =property_getName(properties[i]);[propertiesArray addObject: [NSString stringWithUTF8String: propertyName]];}free(properties);return propertiesArray;
}
  • 调用objc_msgSend方法
//调用对象方法
objc_msgSend(tempIamge, @selector(drawInRect:), CGRectMake(0, 0, 1242, 2208));//调用类方法
//方式1
UIImage *tempImage = ((UIImage *(*)(id, SEL, NSString *)) objc_msgSend)((id)[UIImage class], @selector(imageNamed:), @"test.jpg");
//方式2
UIImage *tempImage = ((UIImage *(*)(id, SEL, NSString *)) objc_msgSend)((id)objc_getClass("UIImage"), sel_registerName("imageNamed:"), @"test.jpg");

http://www.ppmy.cn/ops/16673.html

相关文章

jenkins自动化工具简介

Jenkins 是一个开源的自动化服务器&#xff0c;它允许您自动化各种任务&#xff0c;包括构建、测试和部署软件。它是一个用Java编写的应用程序&#xff0c;可以运行在任何支持Java的平台上。Jenkins 通过其插件系统提供了大量的功能&#xff0c;使其成为一个非常灵活和强大的工…

一般神经网络的微分与网络参数的初始化

(文章的主要内容来自电科的顾亦奇老师的 Mathematical Foundation of Deep Learning, 有部分个人理解) 一般深度神经网络的微分 上周讨论的前向和反向传播算法可以推广到任意深度神经网络的微分。 对于一般的网络来说&#xff0c;可能无法逐层分割&#xff0c;但仍然可以用流…

npm/yarm常用命令

npm命令 标题npm作为嵌入在node中的功能&#xff0c;两个起到相辅相成作用&#xff0c;所以只要安装了node就可以使用npm&#xff01; 查看nodejs版本&#xff1a; node -v 【或 node --version】 查看nodejs版本&#xff1a; npm -v 查看npm下载仓库地址&#xff1a; npm con…

分布式与微服务区别?

1、概念角度&#xff1a; 分布式&#xff1a;把多个应用部署到多台服务器&#xff08;云&#xff09;上&#xff0c;多个应用之间相互协作&#xff0c;提高系统的扩展性和稳定性。 微服务&#xff1a;是分布式的一种实现方式。 2、粒度划分&#xff1a; 分布式&#x…

基于Python的Sentinel-2 卫星图像NDWI洪水检测

本文希望找到清晰的卫星图像来演示一种区分淹没区和非淹没区的简单方法。幸运的是,Sentinel-2 在 4 月 7 日(洪水前事件)和 17 日(洪水后事件)拍摄了两张图像,迪拜上空大部分没有云。这些图像激发了我写一篇关于使用卫星图像检测洪水事件的故事的兴趣。 在这篇文章中,我…

抖音视频笔记

文章目录 手机录屏如何录入麦克风声音变声 一直不太用抖音等交圈软件。 但是有时想记录下生活中的点滴&#xff0c;比较简单的方式实际就是app&#xff0c;那么了解下吧。 制作完毕后可以保存为草稿&#xff0c;不一定发布的。 手机录屏如何录入麦克风声音 毫无疑问&#xff…

WebGL使用动画库( GSAP 一款基于 JavaScript 的 web动画库)

安装 npm install gsap使用 <template><div></div> </template><script setup> import * as THREE from three; import { OrbitControls } from three/addons/controls/OrbitControls.js; // 导入动画库 import gsap from gsap// 场景 const s…

判断水仙花数(C语言)

一、N-S流程图&#xff1b; 二、运行结果&#xff1b; 三、源代码&#xff1b; # define _CRT_SECURE_NO_WARNINGS # include <stdio.h>int main() {//初始化变量值&#xff1b;int n 0;int b 0;int s 0;int g 0;int m 0;//提示用户&#xff1b;printf("请输入…