我喜欢这个代码:
ZAssert(modelURL, @"Failed to find model URL");
但是我收到了这个错误:
implicit declaration of function ZAssert is invalid in C99
你们中的任何人都知道为什么或如何修复?
答案 0 :(得分:2)
ZAssert
可能是一个断言宏,它从某个地方或文件中复制,现在不属于您的代码库。它很容易执行标准功能,因此您只需将其替换为:
NSAssert(modelURL, @"Failed to find model URL");
将检查是否设置了modelURL,如果没有则抛出异常。
答案 1 :(得分:1)
这是我从Marcus S. Zarra的核心数据手册中找到的ZAsset宏
#ifdef DEBUG
#define MCRelease(x) [x release]
#define DLog(...) NSLog(@"%s(%p) %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__])
#define ALog(...) {NSLog(@"%s(%p) %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__]);[[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__ encoding:NSUTF8StringEncoding] file:[NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding] lineNumber:__LINE__ description:__VA_ARGS__];}
#else
#define MCRelease(x) [x release], x = nil
#define DLog(...) do { } while (0)
#ifndef NS_BLOCK_ASSERTIONS
#define NS_BLOCK_ASSERTIONS
#endif
#define ALog(...) NSLog(@"%s(%p) %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__])
#endif
#define ZAssert(condition, ...) do { if (!(condition)) { ALog(__VA_ARGS__); }} while(0)