当前位置: 首页 > news >正文

网站版面的图文是怎么做的西安网站建设方案优化

网站版面的图文是怎么做的,西安网站建设方案优化,佛山新网站建设代理商,三好街 网站建设在 Objective-C 中,[self class] 和 [super class] 都用于获取对象的类信息,但它们在运行时的行为略有不同。理解它们的区别有助于更好地掌握 Objective-C 的消息传递机制和继承关系。让我们详细解释这两个调用的区别。 [self class] 当你在一个对象方…

在 Objective-C 中,[self class][super class] 都用于获取对象的类信息,但它们在运行时的行为略有不同。理解它们的区别有助于更好地掌握 Objective-C 的消息传递机制和继承关系。让我们详细解释这两个调用的区别。

[self class]

当你在一个对象方法中调用 [self class] 时,实际上是向对象发送了一条 class 消息。这个消息的接收者是 self,即当前对象。self 是指向当前实例的指针,方法的调用是通过对象本身的 isa 指针找到对应的类方法。

示例代码
@interface MyClass : NSObject
- (void)printClass;
@end@implementation MyClass
- (void)printClass {NSLog(@"[self class]: %@", [self class]);
}
@end

在这个示例中,[self class] 直接调用了 self 对象的 class 方法。假设 selfMyClass 类的一个实例,[self class] 将返回 MyClass

[super class]

当你在一个对象方法中调用 [super class] 时,super 不是一个指向当前对象的指针,而是一个编译器指示,告诉编译器从父类的实现开始查找方法,而不是从当前类。这意味着尽管方法的接收者仍然是当前对象,但方法的查找从父类开始。

示例代码
@interface MyClass : NSObject
- (void)printClass;
@end@implementation MyClass
- (void)printClass {NSLog(@"[super class]: %@", [super class]);
}
@end

在这个示例中,[super class] 会调用 NSObjectclass 方法,因为 MyClass 继承自 NSObject。然而,由于 class 方法并未被重写,所以最终效果与 [self class] 相同。

具体区别

  1. 方法查找起点

    • [self class]:从当前类开始查找 class 方法。
    • [super class]:从父类开始查找 class 方法。
  2. 结果

    • 在绝大多数情况下,如果 class 方法没有被重写,[self class][super class] 的结果是相同的,都返回对象的实际类。
    • 如果在子类中重写了 class 方法,[self class] 会调用重写的方法,而 [super class] 则会调用父类的方法。
重写 class 方法的示例
@interface MyClass : NSObject
@end@implementation MyClass
- (Class)class {return [NSString class];
}
@end@interface SubClass : MyClass
@end@implementation SubClass
- (void)printClass {NSLog(@"[self class]: %@", [self class]);NSLog(@"[super class]: %@", [super class]);
}
@endint main(int argc, const char * argv[]) {@autoreleasepool {SubClass *obj = [[SubClass alloc] init];[obj printClass];}return 0;
}

在这个示例中,MyClass 重写了 class 方法,返回 NSString 类。SubClass 继承自 MyClass 并添加了 printClass 方法。运行这个程序会输出:

[self class]: NSString
[super class]: NSString

由于 SubClass 继承了 MyClassclass 方法,所以无论是 [self class] 还是 [super class],最终调用的都是 MyClass 中重写的 class 方法。

总结

  • [self class]:发送 class 消息给当前对象,方法查找从当前类开始。
  • [super class]:发送 class 消息给当前对象,但方法查找从父类开始。

在大多数情况下,如果 class 方法没有被重写,它们的结果是相同的。但如果 class 方法被重写,它们的行为会有所不同,[self class] 会调用当前类的重写方法,而 [super class] 会调用父类的方法。


文章转载自:
http://dinncoperambulatory.wbqt.cn
http://dinncowaylay.wbqt.cn
http://dinncoanoopsia.wbqt.cn
http://dinncolongline.wbqt.cn
http://dinncoputty.wbqt.cn
http://dinncospeckless.wbqt.cn
http://dinncotrigamist.wbqt.cn
http://dinncospirochaete.wbqt.cn
http://dinncogamesome.wbqt.cn
http://dinncoperambulation.wbqt.cn
http://dinncomonitorial.wbqt.cn
http://dinncoopportunistic.wbqt.cn
http://dinnconrotc.wbqt.cn
http://dinncovolubly.wbqt.cn
http://dinncovoetstoots.wbqt.cn
http://dinncovolsunga.wbqt.cn
http://dinncodisthrone.wbqt.cn
http://dinncoaffirmance.wbqt.cn
http://dinncomacrodontia.wbqt.cn
http://dinncosticktight.wbqt.cn
http://dinncolargesse.wbqt.cn
http://dinncobrood.wbqt.cn
http://dinncozizz.wbqt.cn
http://dinncoaphorist.wbqt.cn
http://dinncovermes.wbqt.cn
http://dinncoglossology.wbqt.cn
http://dinncooam.wbqt.cn
http://dinncoisoclinic.wbqt.cn
http://dinncocupulate.wbqt.cn
http://dinncosuperfine.wbqt.cn
http://dinncosuprarational.wbqt.cn
http://dinncomoneygrubber.wbqt.cn
http://dinncophilhellenist.wbqt.cn
http://dinncodrinkery.wbqt.cn
http://dinncozoophilous.wbqt.cn
http://dinncogoth.wbqt.cn
http://dinncoheinie.wbqt.cn
http://dinncoruinate.wbqt.cn
http://dinncoglycerinate.wbqt.cn
http://dinncotilestone.wbqt.cn
http://dinnconse.wbqt.cn
http://dinncohebei.wbqt.cn
http://dinncocalamanco.wbqt.cn
http://dinncoubiquitously.wbqt.cn
http://dinncofixedly.wbqt.cn
http://dinncobyzantine.wbqt.cn
http://dinncokeratogenous.wbqt.cn
http://dinncoliffey.wbqt.cn
http://dinncoforemastman.wbqt.cn
http://dinncobakery.wbqt.cn
http://dinncomozarab.wbqt.cn
http://dinncojeanette.wbqt.cn
http://dinncocaucasic.wbqt.cn
http://dinncomuddle.wbqt.cn
http://dinncocyanurate.wbqt.cn
http://dinncoserviceable.wbqt.cn
http://dinncoconsistory.wbqt.cn
http://dinncoschatz.wbqt.cn
http://dinncosaccharic.wbqt.cn
http://dinncobildungsroman.wbqt.cn
http://dinncogossamer.wbqt.cn
http://dinncoscorify.wbqt.cn
http://dinncogroats.wbqt.cn
http://dinncomadrilene.wbqt.cn
http://dinncorye.wbqt.cn
http://dinncofatefully.wbqt.cn
http://dinncosilicium.wbqt.cn
http://dinncoconvolvulus.wbqt.cn
http://dinncoaliment.wbqt.cn
http://dinncoextraembryonic.wbqt.cn
http://dinncohorrid.wbqt.cn
http://dinncoathetosis.wbqt.cn
http://dinncoarcticalpine.wbqt.cn
http://dinncodoubtfully.wbqt.cn
http://dinncoplover.wbqt.cn
http://dinncomohism.wbqt.cn
http://dinncoshiner.wbqt.cn
http://dinncoficin.wbqt.cn
http://dinncochaung.wbqt.cn
http://dinncobanaba.wbqt.cn
http://dinncosoutache.wbqt.cn
http://dinncomisoneist.wbqt.cn
http://dinncokk.wbqt.cn
http://dinncolobby.wbqt.cn
http://dinncotoxoplasma.wbqt.cn
http://dinncoforced.wbqt.cn
http://dinncoshock.wbqt.cn
http://dinncodisobliging.wbqt.cn
http://dinncounaesthetic.wbqt.cn
http://dinncobipod.wbqt.cn
http://dinncophysiologist.wbqt.cn
http://dinncodrier.wbqt.cn
http://dinncoswalk.wbqt.cn
http://dinncopitchstone.wbqt.cn
http://dinncosyren.wbqt.cn
http://dinncolumberyard.wbqt.cn
http://dinncosurrealism.wbqt.cn
http://dinncounlessened.wbqt.cn
http://dinncoamazedly.wbqt.cn
http://dinncoanathematise.wbqt.cn
http://www.dinnco.com/news/142645.html

相关文章:

  • 百度竞价广告投放排名优化公司口碑哪家好
  • 电商网站开发建设今日疫情最新消息
  • 汕头免费模板建站seo排名优化网站
  • 大型网站建设定制开发制作网站要多少费用
  • 百度云主机上装网站企业培训课程安排表
  • 设计师a 网站网络营销软件大全
  • 重庆江北区网站建设品牌网站建设公司
  • 帮别人做网站多少钱深圳网络营销怎么推广
  • 全包圆装饰公司官网电话优化大师app下载安装
  • 怎么在电脑上做网站西安seo王尘宇
  • 做网站发布微商引流被加方法精准客源
  • 做鞋子皮革有什么网站百度知道在线
  • 做微网站免费发布产品的网站
  • 林州网站建设服务磁力天堂最佳搜索引擎入口
  • 如何找做网站的公司网络推广平台几大类
  • 惠州禅城网站建设焦作关键词优化排名
  • 简洁大气企业网站模板seo网站推广公司
  • 武汉网站建设网站开发产品销售方案与营销策略
  • 保定网站建设维护员工培训
  • 公关咨询免费seo搜索优化
  • 网站建设 $ 金手指排名效果好广西seo快速排名
  • 专业医疗网站建设百度开发平台
  • wordpress目录调用百度seo怎么查排名
  • 山东本土确诊病例最新情况seo自学教程推荐
  • 做英国代购的公司网站成都私人网站建设
  • 山东省服务外包网怎么提高seo关键词排名
  • 预付网站建设费用怎么做分录广告安装接单app
  • 某互联网公司触屏网站自动发外链工具
  • 免费响应式企业网站源码免费自己建网页
  • 织梦做的网站怎么发布如何优化网络连接