iOS NSObject Class 详解
来源:互联网 发布:苹果cms 视频云解析 编辑:程序博客网 时间:2024/04/24 13:22
Overview
NSObject
is the root class of most Objective-C class hierarchies. Through NSObject
, objects inherit a basic interface to the runtime system and the ability to behave as Objective-C objects.
Class Methods
alloc
Returns a new instance of the receiving class.
Return Value
A new instance of the receiver.
Discussion
The isa
instance variable of the new instance is initialized to a data structure that describes the class; memory for all other instance variables is set to 0
.
You must use an init...
method to complete the initialization process. For example:
TheClass *newObject = [[TheClass alloc] init];
Do not override alloc
to include initialization code. Instead, implement class-specific versions of init...
methods.
For historical reasons, alloc
invokes allocWithZone:
.
allocWithZone:
Returns a new instance of the receiving class.
Parameters
- zone
This parameter is ignored.
Return Value
A new instance of the receiver.
Discussion
The isa
instance variable of the new instance is initialized to a data structure that describes the class; memory for all other instance variables is set to 0
.
You must use an init...
method to complete the initialization process. For example:
TheClass *newObject = [[TheClass allocWithZone:nil] init];
Do not override allocWithZone:
to include any initialization code. Instead, class-specific versions of init...
methods.
This method exists for historical reasons; memory zones are no longer used by Objective-C.
performSelector:withObject:afterDelay:
Invokes a method of the receiver on the current thread using the default mode after a delay.
Parameters
- aSelector
A selector that identifies the method to invoke. The method should not have a significant return value and should take a single argument of type id, or no arguments.
- anArgument
The argument to pass to the method when it is invoked. Pass
nil
if the method does not take an argument.- delay
The minimum time before which the message is sent. Specifying a delay of 0 does not necessarily cause the selector to be performed immediately. The selector is still queued on the thread’s run loop and performed as soon as possible.
Discussion
This method sets up a timer to perform the aSelector message on the current thread’s run loop. The timer is configured to run in the default mode (NSDefaultRunLoopMode
). When the timer fires, the thread attempts to dequeue the message from the run loop and perform the selector. It succeeds if the run loop is running and in the default mode; otherwise, the timer waits until the run loop is in the default mode.
If you want the message to be dequeued when the run loop is in a mode other than the default mode, use the performSelector:withObject:afterDelay:inModes:
method instead. If you are not sure whether the current thread is the main thread, you can use the performSelectorOnMainThread:withObject:waitUntilDone:
or performSelectorOnMainThread:withObject:waitUntilDone:modes:
method to guarantee that your selector executes on the main thread. To cancel a queued message, use the cancelPreviousPerformRequestsWithTarget: or cancelPreviousPerformRequestsWithTarget:selector:object: method.
- iOS NSObject Class 详解
- iOS: NSObject的方法class
- ios开发 之 NSObject详解
- 什么是NSObject?NSObject 详解
- iOS NSObject
- iOS NSObject
- NSObject详解
- NSObject详解
- NSObject详解
- NSObject详解
- NSObject详解
- NSObject Class 浅析
- iOS [<NSObject 0x170204110> setValue:forUndefineKey:]: this class is not key value coding-compliant
- iOS id、NSObject、id<NSObject>的区别
- iOS之id ,NSObject, id<NSObject>区别
- IOS学习之NSObject
- iOS 根类NSObject
- iOS NSObject api注解
- Linux学习总结 Part-IV
- 图解Eclipse开发Java环境配置
- java验证码
- 黑马程序员:多线程
- POJ 1422 Air Raid
- iOS NSObject Class 详解
- NBNS简析
- Linux C中令人讨厌的段错误
- 中国最具声望16所大学,国际排名逐个数~
- POJ 3090 Visible Lattice Points
- linux HZ Tick Jiffies
- boot windows from linux
- Java 复用类
- POJ 2449 Remmarguts' Date 求K短路