Skip to content

Instantly share code, notes, and snippets.

// 監聽 UITextField 當內文有改變的時候,會執行內部 function
[[self.textView rac_signalForControlEvents:UIControlEventEditingChanged] subscribeNext:^(__kindof UIControl * _Nullable x) {
NSLog(@"text change");
}];
// 監聽 button UIControlEventTouchUpInside 狀態
[[self.btnButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
NSLog(@"button click");
}];
@SunXiaoShan
SunXiaoShan / SignalExample.m
Created July 7, 2017 08:34
SignalExample - ReactiveObjC
// create signnal
RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber> _Nonnull subscriber) {
[subscriber sendNext:@"message"];
return nil;
}];
// subscribe notification
RACDisposable *disposable = [signal subscribeNext:^(id _Nullable x) {
NSLog(@"content:%@", x);
}];
// create a signal
RACSubject *subject = [RACSubject subject];
// subscribe notification
[subject subscribeNext:^(id _Nullable x) {
NSLog(@"content 2:%@", x);
}];
// send message
[subject sendNext:@"message 2"];
@SunXiaoShan
SunXiaoShan / RAC_array.m
Created July 7, 2017 08:53
RAC_array_example
// loop all element
NSArray *array = @[@"1", @"2", @"3", @"4", @"5"];
[array.rac_sequence.signal subscribeNext:^(id _Nullable x) {
NSLog(@"element:%@", x);
}];
// output
// element:1
// element:2
// element:3
[RACObserve(objA, strContent) subscribeNext:^(id x) {
NSLog(@"objA : %@",x);
[self.labelView setText:x];
}];
@SunXiaoShan
SunXiaoShan / ObserveButtonParameter.m
Created July 7, 2017 09:34
ObserveButtonParameter
RAC(_btnButton, hidden) = [RACSignal
combineLatest:@[_textView.rac_textSignal]
reduce:^id _Nullable(NSString * text) {
return @(text.length==0);
}];
@SunXiaoShan
SunXiaoShan / RAC_notification.m
Created July 7, 2017 09:38
RAC_notification
[[[NSNotificationCenter defaultCenter] rac_addObserverForName:UIKeyboardDidShowNotification object:nil] subscribeNext:^(NSNotification * _Nullable x) {
NSLog(@"keyboard - \n%@", x);
}];
@SunXiaoShan
SunXiaoShan / RAC_button_click.m
Created July 7, 2017 09:43
RAC_button_click
[[self.btnButton rac_signalForSelector:@selector(actionButton:)] subscribeNext:^(RACTuple * _Nullable x) {
NSLog(@"button click..");
}];
@SunXiaoShan
SunXiaoShan / SimpleDemo.m
Last active July 8, 2017 19:42
RAC_SimpleDemo
@interface Model:NSObject
@property (strong, nonatomic) NSString *content;
@end
@implementation Model
@end
@interface ViewModel:NSObject
@property (strong, nonatomic) NSString *content;
- (void) execute:(NSString *)content;
// JAVA
// QUESTION 1
static String getReverseString(String input) {
char[] in = input.toCharArray();
char buff;
for (int i=0,j=input.length()-1; i<input.length()/2;i++,j--) {
buff = in[i];
in[i] = in[j];
in[j] = buff;
}