NSNotificationCenter+YYAdd.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // NSNotificationCenter+YYAdd.h
  3. // YYKit <https://github.com/ibireme/YYKit>
  4. //
  5. // Created by ibireme on 13/8/24.
  6. // Copyright (c) 2015 ibireme.
  7. //
  8. // This source code is licensed under the MIT-style license found in the
  9. // LICENSE file in the root directory of this source tree.
  10. //
  11. #import <Foundation/Foundation.h>
  12. NS_ASSUME_NONNULL_BEGIN
  13. /**
  14. Provide some method for `NSNotificationCenter`
  15. to post notification in different thread.
  16. */
  17. @interface NSNotificationCenter (YYAdd)
  18. /**
  19. Posts a given notification to the receiver on main thread.
  20. If current thread is main thread, the notification is posted synchronously;
  21. otherwise, is posted asynchronously.
  22. @param notification The notification to post.
  23. An exception is raised if notification is nil.
  24. */
  25. - (void)postNotificationOnMainThread:(NSNotification *)notification;
  26. /**
  27. Posts a given notification to the receiver on main thread.
  28. @param notification The notification to post.
  29. An exception is raised if notification is nil.
  30. @param wait A Boolean that specifies whether the current thread blocks
  31. until after the specified notification is posted on the
  32. receiver on the main thread. Specify YES to block this
  33. thread; otherwise, specify NO to have this method return
  34. immediately.
  35. */
  36. - (void)postNotificationOnMainThread:(NSNotification *)notification
  37. waitUntilDone:(BOOL)wait;
  38. /**
  39. Creates a notification with a given name and sender and posts it to the
  40. receiver on main thread. If current thread is main thread, the notification
  41. is posted synchronously; otherwise, is posted asynchronously.
  42. @param name The name of the notification.
  43. @param object The object posting the notification.
  44. */
  45. - (void)postNotificationOnMainThreadWithName:(NSString *)name
  46. object:(nullable id)object;
  47. /**
  48. Creates a notification with a given name and sender and posts it to the
  49. receiver on main thread. If current thread is main thread, the notification
  50. is posted synchronously; otherwise, is posted asynchronously.
  51. @param name The name of the notification.
  52. @param object The object posting the notification.
  53. @param userInfo Information about the the notification. May be nil.
  54. */
  55. - (void)postNotificationOnMainThreadWithName:(NSString *)name
  56. object:(nullable id)object
  57. userInfo:(nullable NSDictionary *)userInfo;
  58. /**
  59. Creates a notification with a given name and sender and posts it to the
  60. receiver on main thread.
  61. @param name The name of the notification.
  62. @param object The object posting the notification.
  63. @param userInfo Information about the the notification. May be nil.
  64. @param wait A Boolean that specifies whether the current thread blocks
  65. until after the specified notification is posted on the
  66. receiver on the main thread. Specify YES to block this
  67. thread; otherwise, specify NO to have this method return
  68. immediately.
  69. */
  70. - (void)postNotificationOnMainThreadWithName:(NSString *)name
  71. object:(nullable id)object
  72. userInfo:(nullable NSDictionary *)userInfo
  73. waitUntilDone:(BOOL)wait;
  74. @end
  75. NS_ASSUME_NONNULL_END