NSObject(FWApplication)

@interface NSObject (FWApplication)

可使用NS_UNAVAILABLE标记方法不可用,NS_DESIGNATED_INITIALIZER标记默认init方法。 注意load可能被子类super调用导致调用多次,需dispatch_once避免;而initialize如果子类不实现,默认会调用父类initialize,也会导致调用多次,可判断class或dispatch_once避免

Archive

  • 使用NSKeyedArchiver和NSKeyedUnarchiver深拷对象

    Declaration

    Objective-C

    - (nullable id)fw_archiveCopy;

    Return Value

    出错返回nil

Block

  • 延迟delay秒后主线程执行,返回可取消的block,对象范围

    Declaration

    Objective-C

    - (nonnull id)fw_performBlock:(nonnull void (^)(id _Nonnull __strong))block
                       afterDelay:(NSTimeInterval)delay;
  • 延迟delay秒后后台线程执行,返回可取消的block,对象范围

    Declaration

    Objective-C

    - (nonnull id)fw_performBlockInBackground:
                      (nonnull void (^)(id _Nonnull __strong))block
                                   afterDelay:(NSTimeInterval)delay;
  • 延迟delay秒后指定线程执行,返回可取消的block,对象范围

    Declaration

    Objective-C

    - (nonnull id)fw_performBlock:(nonnull void (^)(id _Nonnull __strong))block
                          onQueue:(nonnull dispatch_queue_t)queue
                       afterDelay:(NSTimeInterval)delay;
  • 同步方式执行异步block,阻塞当前线程(信号量),异步block必须调用completionHandler,全局范围

    Declaration

    Objective-C

    - (void)fw_syncPerformAsyncBlock:
        (nonnull void (^)(void (^_Nonnull __strong)(void)))asyncBlock;
  • 同一个identifier仅执行一次block,对象范围

    Declaration

    Objective-C

    - (void)fw_performOnce:(nonnull NSString *)identifier
                 withBlock:(nonnull void (^)(void))block;
  • 重试方式执行异步block,直至成功或者次数为0或者超时,完成后回调completion。block必须调用completionHandler,参数示例:重试4次|超时8秒|延迟2秒

    Declaration

    Objective-C

    - (void)fw_performBlock:(nonnull void (^)(void (^_Nonnull __strong)(
                                BOOL, id _Nullable __strong)))block
                 completion:(nonnull void (^)(BOOL,
                                              id _Nullable __strong))completion
                 retryCount:(NSUInteger)retryCount
            timeoutInterval:(NSTimeInterval)timeoutInterval
              delayInterval:(NSTimeInterval)delayInterval;
  • 延迟delay秒后主线程执行,返回可取消的block,全局范围

    Declaration

    Objective-C

    + (nonnull id)fw_performBlock:(nonnull void (^)(void))block
                       afterDelay:(NSTimeInterval)delay;
  • 延迟delay秒后后台线程执行,返回可取消的block,全局范围

    Declaration

    Objective-C

    + (nonnull id)fw_performBlockInBackground:(nonnull void (^)(void))block
                                   afterDelay:(NSTimeInterval)delay;
  • 延迟delay秒后指定线程执行,返回可取消的block,全局范围

    Declaration

    Objective-C

    + (nonnull id)fw_performBlock:(nonnull void (^)(void))block
                          onQueue:(nonnull dispatch_queue_t)queue
                       afterDelay:(NSTimeInterval)delay;
  • 取消指定延迟block,全局范围

    Declaration

    Objective-C

    + (void)fw_cancelBlock:(nonnull id)block;
  • 同步方式执行异步block,阻塞当前线程(信号量),异步block必须调用completionHandler,全局范围

    Declaration

    Objective-C

    + (void)fw_syncPerformAsyncBlock:
        (nonnull void (^)(void (^_Nonnull __strong)(void)))asyncBlock;
  • 同一个identifier仅执行一次block,全局范围

    Declaration

    Objective-C

    + (void)fw_performOnce:(nonnull NSString *)identifier
                 withBlock:(nonnull void (^)(void))block;
  • 重试方式执行异步block,直至成功或者次数为0或者超时,完成后回调completion。block必须调用completionHandler,参数示例:重试4次|超时8秒(0不限制)|延迟2秒

    Declaration

    Objective-C

    + (void)fw_performBlock:(nonnull void (^)(void (^_Nonnull __strong)(
                                BOOL, id _Nullable __strong)))block
                 completion:(nonnull void (^)(BOOL,
                                              id _Nullable __strong))completion
                 retryCount:(NSUInteger)retryCount
            timeoutInterval:(NSTimeInterval)timeoutInterval
              delayInterval:(NSTimeInterval)delayInterval;
  • 执行轮询block任务,返回任务Id可取消

    Declaration

    Objective-C

    + (nonnull NSString *)fw_performTask:(nonnull void (^)(void))task
                                   start:(NSTimeInterval)start
                                interval:(NSTimeInterval)interval
                                 repeats:(BOOL)repeats
                                   async:(BOOL)async;
  • 指定任务Id取消轮询任务

    Declaration

    Objective-C

    + (void)fw_cancelTask:(nonnull NSString *)taskId;

Debug

  • 获取当前对象的所有 @property、方法,父类的方法也会分别列出

    Declaration

    Objective-C

    @property (nonatomic, copy, readonly) NS_REFINED_FOR_SWIFT NSString *fw_methodList;
  • 获取当前对象的所有 @property、方法,不包含父类的

    Declaration

    Objective-C

    @property (nonatomic, copy, readonly) NS_REFINED_FOR_SWIFT NSString *fw_shortMethodList;
  • 当前对象的所有 Ivar 变量

    Declaration

    Objective-C

    @property (nonatomic, copy, readonly) NS_REFINED_FOR_SWIFT NSString *fw_ivarList;