我有一个NSOperationQueue,maxConcurrentOperationCount = 1,
和自定义NSOperation有一个属性是块,
当iOS 9.x中的NSOperationQueue addOperation,应用程序崩溃时,
NSOperation不是零.
以下是Apple崩溃报告,但我不能再出现:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x1000000013ed199e
0 Foundation 0x0000000182f3b4e8 ____addOperations_block_invoke607 + 524 (NSOperation.m:193)
1 Foundation 0x0000000182f3b488 ____addOperations_block_invoke607 + 428 (NSOperation.m:204)
2 Foundation 0x0000000182f26170 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:usingBlock:] + 672 (NSKeyValueObserving.m:2406)
3 Foundation 0x0000000182e7afc0 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:] + 64 (NSKeyValueObserving.m:2432)
4 Foundation 0x0000000182f392e4 __addOperations + 1400 (NSOperation.m:2100)
Run Code Online (Sandbox Code Playgroud)
谢谢!
任何人:
我想使用一个宏来打印日志,接下来,
#define isaObject(parameter) _Generic((parameter), id: YES, id __strong: YES, default: NO)
#define kNSLog(parameter) do \
{ \
BOOL is = isaObject((parameter)); \
if (is) \
{ \
NSLog(@"----Yes : %@", parameter); \
} \
else \
{ \
NSLog(@"----No : %d", parameter); \
} \
} while (NO)
int i = 99;
NSString * s = @"abcd";
kNSLog(i);
kNSLog(s);
Run Code Online (Sandbox Code Playgroud)
然后,编译器发出警告"Format指定类型'int',但参数的类型为'NSString*'".
怎么修改,拜托?
我有一个NSURLProtocol的子类,NSURLConnection运作良好。
并且[NSURLSession sharedSession]也很好用。
但是,[NSURLSession sessionWithConfiguration:configuration]不起作用,
我叫[NSURLProtocol registerClass:NSURLProtocolSubclass.class];
怎么了
NSString * stringUrl = @"https://www.apple.com/";
NSURL * url = [NSURL URLWithString:stringUrl];
NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url];
urlRequest.HTTPMethod = @"GET";
NSURLSessionConfiguration * configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration];
configuration.timeoutIntervalForResource = 20.0;
//this can work, but I cann't edit.
//configuration.protocolClasses = @[NSURLProtocolSubclass.class];
//this can work.
NSURLSession * urlSession = [NSURLSession sharedSession];
//this not work.
//NSURLSession * urlSession = [NSURLSession sessionWithConfiguration:configuration];
//Task.
NSURLSessionDataTask * task = [urlSession dataTaskWithRequest:urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSHTTPURLResponse …Run Code Online (Sandbox Code Playgroud)