Skip to content

Commit 78c5517

Browse files
Merge pull request #8 from LeoMobileDeveloper/v0.3.0
V0.3.0
2 parents fd5e28d + d060032 commit 78c5517

10 files changed

Lines changed: 105 additions & 5 deletions

File tree

Demo/Base.lproj/Main.storyboard

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="4To-HN-DqI">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="4To-HN-DqI">
33
<device id="retina4_7" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
66
<dependencies>
77
<deployment identifier="iOS"/>
8-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
99
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1010
</dependencies>
1111
<scenes>
@@ -58,18 +58,27 @@
5858
</connections>
5959
</button>
6060
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="DAf-9g-R9z">
61-
<rect key="frame" x="115" y="274.5" width="144" height="30"/>
61+
<rect key="frame" x="115.5" y="274.5" width="144" height="30"/>
6262
<state key="normal" title="Dispatch Notification"/>
6363
<connections>
6464
<action selector="dispatchNotification:" destination="UfB-hx-yKX" eventType="touchUpInside" id="XZN-wZ-wqm"/>
6565
</connections>
6666
</button>
67+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Gzk-EX-vLV">
68+
<rect key="frame" x="134.5" y="356" width="106" height="30"/>
69+
<state key="normal" title="Dispatch String"/>
70+
<connections>
71+
<action selector="dispatchString:" destination="UfB-hx-yKX" eventType="touchUpInside" id="8D8-wz-two"/>
72+
</connections>
73+
</button>
6774
</subviews>
6875
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
6976
<constraints>
7077
<constraint firstItem="MXl-SO-nrb" firstAttribute="centerY" secondItem="gBg-dr-YJh" secondAttribute="centerY" id="0ee-IM-VqN"/>
78+
<constraint firstItem="Gzk-EX-vLV" firstAttribute="top" secondItem="MXl-SO-nrb" secondAttribute="bottom" constant="7.5" id="CxM-iL-nxJ"/>
7179
<constraint firstItem="MXl-SO-nrb" firstAttribute="centerX" secondItem="gBg-dr-YJh" secondAttribute="centerX" id="DQZ-jE-IBh"/>
7280
<constraint firstItem="DAf-9g-R9z" firstAttribute="centerX" secondItem="MXl-SO-nrb" secondAttribute="centerX" id="Dz4-ce-Yux"/>
81+
<constraint firstItem="Gzk-EX-vLV" firstAttribute="centerX" secondItem="MXl-SO-nrb" secondAttribute="centerX" id="fN7-kG-dEe"/>
7382
<constraint firstItem="MXl-SO-nrb" firstAttribute="top" secondItem="DAf-9g-R9z" secondAttribute="bottom" constant="14" id="uup-6p-Jot"/>
7483
</constraints>
7584
</view>

Demo/DemoViewController.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ - (void)viewDidLoad {
3232
next:^(QTAppLifeCircleEvent *event) {
3333
NSLog(@"DemoViewController: %@",event.type);
3434
}];
35+
[QTSubName(self, @"ButtonClickedEvent") next:^(NSString *event) {
36+
NSLog(@"%@",@"Receive String Event");
37+
}];
3538
}
3639

3740

@@ -47,6 +50,10 @@ - (IBAction)dispatchEvent:(id)sender {
4750
[[QTEventBus shared] dispatch:event];
4851
}
4952

53+
- (IBAction)dispatchString:(id)sender {
54+
[[QTEventBus shared] dispatch:@"ButtonClickedEvent"];
55+
}
56+
5057
- (void)dealloc{
5158
NSLog(@"Dealloc: %@",NSStringFromClass(self.class));
5259
}

QTEventBus.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'QTEventBus'
3-
s.version = '0.2.4'
3+
s.version = '0.3.0'
44
s.summary = '优雅的处理全局事件'
55
s.description = <<-DESC
66
优雅的处理全局事件,类型安全,支持同步/异步发送,同步/异步监听

QTEventBus.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
B34B70D720C4DC65006339C6 /* QTDisposeBag.h in Headers */ = {isa = PBXBuildFile; fileRef = B34B70D520C4DC65006339C6 /* QTDisposeBag.h */; };
2929
B34B70D820C4DC65006339C6 /* QTDisposeBag.m in Sources */ = {isa = PBXBuildFile; fileRef = B34B70D620C4DC65006339C6 /* QTDisposeBag.m */; };
3030
B36007B0211C4D3100250A2B /* UserService.m in Sources */ = {isa = PBXBuildFile; fileRef = B36007AF211C4D3100250A2B /* UserService.m */; };
31+
B36440ED21957FFD00D4095B /* NSString+QTEevnt.h in Headers */ = {isa = PBXBuildFile; fileRef = B36440EB21957FFD00D4095B /* NSString+QTEevnt.h */; };
32+
B36440EE21957FFD00D4095B /* NSString+QTEevnt.m in Sources */ = {isa = PBXBuildFile; fileRef = B36440EC21957FFD00D4095B /* NSString+QTEevnt.m */; };
3133
B3C36A7320EDBA2A0087382E /* QTJsonEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = B3C36A7120EDBA2A0087382E /* QTJsonEvent.h */; };
3234
B3C36A7420EDBA2A0087382E /* QTJsonEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = B3C36A7220EDBA2A0087382E /* QTJsonEvent.m */; };
3335
B3CC766B20410C69006CA9C0 /* QTEventBus.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B3CC766120410C69006CA9C0 /* QTEventBus.framework */; };
@@ -108,6 +110,8 @@
108110
B34B70D620C4DC65006339C6 /* QTDisposeBag.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QTDisposeBag.m; sourceTree = "<group>"; };
109111
B36007AE211C4D3100250A2B /* UserService.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UserService.h; sourceTree = "<group>"; };
110112
B36007AF211C4D3100250A2B /* UserService.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UserService.m; sourceTree = "<group>"; };
113+
B36440EB21957FFD00D4095B /* NSString+QTEevnt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSString+QTEevnt.h"; sourceTree = "<group>"; };
114+
B36440EC21957FFD00D4095B /* NSString+QTEevnt.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSString+QTEevnt.m"; sourceTree = "<group>"; };
111115
B3C36A7120EDBA2A0087382E /* QTJsonEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QTJsonEvent.h; sourceTree = "<group>"; };
112116
B3C36A7220EDBA2A0087382E /* QTJsonEvent.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QTJsonEvent.m; sourceTree = "<group>"; };
113117
B3CC766120410C69006CA9C0 /* QTEventBus.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = QTEventBus.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -212,6 +216,8 @@
212216
B34B70D620C4DC65006339C6 /* QTDisposeBag.m */,
213217
B3C36A7120EDBA2A0087382E /* QTJsonEvent.h */,
214218
B3C36A7220EDBA2A0087382E /* QTJsonEvent.m */,
219+
B36440EB21957FFD00D4095B /* NSString+QTEevnt.h */,
220+
B36440EC21957FFD00D4095B /* NSString+QTEevnt.m */,
215221
);
216222
path = Core;
217223
sourceTree = "<group>";
@@ -303,6 +309,7 @@
303309
52182D2F212039D0007E39BE /* QTAppModuleManager.h in Headers */,
304310
52182D2C212039D0007E39BE /* QTAppDelegate.h in Headers */,
305311
52182D2D212039D0007E39BE /* QTAppEvents.h in Headers */,
312+
B36440ED21957FFD00D4095B /* NSString+QTEevnt.h in Headers */,
306313
B3CC767220410C69006CA9C0 /* QTEventBus.h in Headers */,
307314
B34B70D720C4DC65006339C6 /* QTDisposeBag.h in Headers */,
308315
52182D31212039D0007E39BE /* QTAppModule.h in Headers */,
@@ -466,6 +473,7 @@
466473
B3C36A7420EDBA2A0087382E /* QTJsonEvent.m in Sources */,
467474
52182D32212039D0007E39BE /* QTAppEvents.m in Sources */,
468475
B3CC768020410E5F006CA9C0 /* QTEventBusCollection.m in Sources */,
476+
B36440EE21957FFD00D4095B /* NSString+QTEevnt.m in Sources */,
469477
B3D13C2A20C1512C008CEE54 /* NSObject+QTEventBus.m in Sources */,
470478
52182D30212039D0007E39BE /* QTAppDelegate.m in Sources */,
471479
B34B70D820C4DC65006339C6 /* QTDisposeBag.m in Sources */,

QTEventBusTests/QTBasicTests.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ - (void)tearDown {
3030
_eventBus = nil;
3131
}
3232

33+
- (void)testStringEvent{
34+
XCTestExpectation * expectation = [self expectationWithDescription:@"String test"];
35+
id<QTEventToken> token;
36+
token = [[self subscribeName:@"Event" on:self.eventBus] next:^(NSString *event) {
37+
XCTAssert([event isEqualToString:@"Event"]);
38+
[token dispose];
39+
[expectation fulfill];
40+
}];
41+
[self.eventBus dispatch:@"Event"];
42+
[self waitForExpectationsWithTimeout:10 handler:^(NSError * _Nullable error) {
43+
44+
}];
45+
}
46+
3347
- (void)testNormalEvent{
3448
XCTestExpectation * expectation = [self expectationWithDescription:@"Normal test"];
3549
id<QTEventToken> token;

Sources/Core/NSObject+QTEventBus.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424
*/
2525
- (QTEventSubscriberMaker *)subscribe:(Class)eventClass on:(QTEventBus *)bus;
2626

27+
/**
28+
在EventBus单例子监听指定字符串事件
29+
*/
30+
- (QTEventSubscriberMaker<NSString *> *)subscribeName:(NSString *)eventName;
31+
32+
/**
33+
在bus上监听指定字符串时间
34+
*/
35+
- (QTEventSubscriberMaker<NSString *> *)subscribeName:(NSString *)eventName on:(QTEventBus *)bus;
36+
2737
/**
2838
释放池
2939
*/

Sources/Core/NSObject+QTEventBus.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import "QTEventBus.h"
1111
#import <objc/runtime.h>
1212
#import <UIKit/UIKit.h>
13+
#import "NSString+QTEevnt.h"
1314

1415
static const char event_bus_disposeContext;
1516

@@ -24,6 +25,16 @@ - (QTDisposeBag *)eb_disposeBag{
2425
return bag;
2526
}
2627

28+
- (QTEventSubscriberMaker *)subscribeName:(NSString *)eventName{
29+
NSParameterAssert(eventName != nil);
30+
return [QTEventBus shared].on(NSString.class).ofSubType(eventName).freeWith(self);
31+
}
32+
33+
- (QTEventSubscriberMaker *)subscribeName:(NSString *)eventName on:(QTEventBus *)bus{
34+
NSParameterAssert(eventName != nil);
35+
return bus.on(NSString.class).ofSubType(eventName).freeWith(self);
36+
}
37+
2738
- (QTEventSubscriberMaker *)subscribe:(Class)eventClass{
2839
return [QTEventBus shared].on(eventClass).freeWith(self);
2940
}

Sources/Core/NSString+QTEevnt.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// NSString+QTEevnt.h
3+
// QTEventBus
4+
//
5+
// Created by Leo on 2018/11/9.
6+
// Copyright © 2018 Leo Huang. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "QTEventTypes.h"
11+
12+
NS_ASSUME_NONNULL_BEGIN
13+
14+
@interface NSString (QTEevnt)<QTEvent>
15+
16+
@end
17+
18+
NS_ASSUME_NONNULL_END

Sources/Core/NSString+QTEevnt.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// NSString+QTEevnt.m
3+
// QTEventBus
4+
//
5+
// Created by Leo on 2018/11/9.
6+
// Copyright © 2018 Leo Huang. All rights reserved.
7+
//
8+
9+
#import "NSString+QTEevnt.h"
10+
11+
@implementation NSString (QTEevnt)
12+
13+
- (NSString *)eventSubType{
14+
return [self copy];
15+
}
16+
17+
+ (Class)eventClass{
18+
return [NSString class];
19+
}
20+
21+
@end

Sources/Core/QTEventBus.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
#import "QTJsonEvent.h"
1212
#import "NSNotification+QTEvent.h"
1313
#import "NSObject+QTEventBus.h"
14+
#import "NSString+QTEevnt.h"
1415

15-
//监听,监听的生命周期和object一样
16+
//单例监听,监听的生命周期和object一样
1617
#define QTSub(_object_,_className_) ((QTEventSubscriberMaker<_className_ *> *)[_object_ subscribe:[_className_ class]])
18+
#define QTSubName(_object_,_name_) ([_object_ subscribeName:_name_])
1719
//异步在主线程监听
1820
#define QTSubMain(_object_,_className_) ([QTSub(_object_, _className_) atQueue:dispatch_get_main_queue()])
1921
//监听NSNotification

0 commit comments

Comments
 (0)