你可能不知道的

    xiaoxiao2021-03-25  129

    1.NSCache

    1>建议做缓存的时候采用 NSCache, 而不是 NSDictionary. 2>大多数情况下, NSCache 的用法与 NSDictionary 一样, 可以调用 objectForKey:, setObject:forKey:, removeObjectForKey: 3>开发者可以在任何线程上不加锁的修改NSCache

    2.NSURLComponents

    它可以很方便的把 URL 分成几个部分, 比如:

    NSString *URLString = @"http://172.0.0.1:8888/api/ios?name=lcn" NSURLComponents *components = [NSURLComponents componentsWithString:URLString]; NSString *host = components.host; NSLog(@"%@", host);

    也可以用它创建或修改 URL

    3.CFStringTransform

    它可以处理非拉丁书写系统(例如:中文)和拉丁字母之间的转换:

    NSMutableString *source = @"点通宝".mutableCopy; // 将中文转换成带声调的拼音 CFStringTransform((__bridge CFMutableStringRef)source, NULL, kCFStringTransformMandarinLatin, NO); NSLog(@"%@", source); // 将拼音的声调去掉 CFStringTransform((__bridge CFMutableStringRef)source, NULL, kCFStringTransformStripDiacritics, NO); NSLog(@"%@", source);

    另: 它不能处理日文(因为日文中可能出现汉字)

    转载请注明原文地址: https://ju.6miu.com/read-9770.html

    最新回复(0)