原来MacOS内置了字典,可以通过API访问,这样验证一个单词是不是有效的英文单词就很简单了:
NSString *word = @"great";
CFRange r = DCSGetTermRangeInString(NULL, (__bridge CFStringRef)word, 0);
if(r.location!=kCFNotFound) NSLog(@"valid word");
else NSLog(@"Invalid word");
API参考文档:
https://developer.apple.com/documentation/coreservices/1450556-dcsgettermrangeinstring?language=objc