美文网首页
NSString+YYAdd的学习2

NSString+YYAdd的学习2

作者: _阿南_ | 来源:发表于2017-10-27 12:18 被阅读41次
图片来之网络

看了NSString的API后才发现
世界是那么的大
大到一篇文章都写不下

路径扩展

NSPathUtilities.h, 路径处理在APP开发中很少用到,一般不保存内容到目录,直接保存在内存中。

+ (NSString *)pathWithComponents:(NSArray<NSString *> *)components;

将数组中的字符串使用"/"符号连接成一个字符串。例如 NSString *path = [NSString pathWithComponents:@[@"home", @"tmp", @"picture"]]; 这显示的字符串为home/tmp/picture

@property (readonly, copy) NSArray<NSString *> *pathComponents;

将路径字符串根据"/"分割,返回包含所有的字符串的数组。 例如“home/tmp/picture”将返回包含“home”,“tmp”和“picture”的字符串的数组。

@property (getter=isAbsolutePath, readonly) BOOL absolutePath;

判断是否为绝对路径。例如:“home/tmp/picture”不是绝对路径,是相对路径。 “/home/tmp/picture”为绝对路径。

@property (readonly, copy) NSString *lastPathComponent;

返回最后路径组成部分。 例如:“home/tmp/picture”返回“picture”。

@property (readonly, copy) NSString *stringByDeletingLastPathComponent;

删除路径的最后部分。 例如: “home/tmp/picture”返回“home/tmp”。

- (NSString *)stringByAppendingPathComponent:(NSString *)str;

在最后添加输入的字符串。例如: 输入的字符串为“my”,那么“home/tmp/picture”追加后为“home/tmp/picture/my”。

@property (readonly, copy) NSString *pathExtension;

返回后缀的字符串。 例如: “home/tmp/picture”返回为空。如果“home/tmp/picture.png”则返回为“png”。

@property (readonly, copy) NSString *stringByDeletingPathExtension;

删除路径的后缀。 例如: "home/tmp/picture.png"返回“home/tmp/picture”。

- (nullable NSString *)stringByAppendingPathExtension:(NSString *)str;

添加后缀。 例如, 后缀为“jpg”,那么"home/tmp/picture"执行返回“home/tmp/picture.jpg”。

@property (readonly, copy) NSString *stringByAbbreviatingWithTildeInPath;

将路径字符串中以NSHomeDirectory()开始的,则NSHomeDirectory()部分替换为"~". 例如: “/Users/arthurwang/Library/Developer/CoreSimulator/Devices/3A7D67DC-0820-46BE-A567-53625AA03CD9/data/Containers/Data/Application/7DA5A209-A876-446F-966F-4FBD380E477F/test/picture” 会输出“~/test/picture”。

@property (readonly, copy) NSString *stringByExpandingTildeInPath;

将“”或“*”展开为NSHomeDirectory()内容。例如: “/app/download”或“sfsdf/app/download”,返回“/Users/arthurwang/Library/Developer/CoreSimulator/Devices/3A7D67DC-0820-46BE-A567-53625AA03CD9/data/Containers/Data/Application/0830128F-2C4C-4BB1-800A-0617E6E2D015/app/download”。

@property (readonly, copy) NSString *stringByStandardizingPath;

返回标准的路径,执行的操作:(1)展开“~”。 (2)路径中“/private/var/automount/”,"/var/automount"或“/private”,如果移除这些路径后,结果字符串为有效的存在的路径,则移除。 (3)移除“//”和"/./"的路径。 (4)如果为绝对路径,那么".."解析为上一级的路径。"."解析为当前的路径。

@property (readonly, copy) NSString *stringByResolvingSymlinksInPath;

解析绝对路径中的符号链接,相对路径不解析。
符号链接,又称为软连接,是一种特殊的符号。

FOUNDATION_EXPORT NSString *NSHomeDirectory(void);
FOUNDATION_EXPORT NSString * _Nullable NSHomeDirectoryForUser(NSString * _Nullable userName);
FOUNDATION_EXPORT NSString *NSTemporaryDirectory(void);

获取主路径。 例如:NSHomeDirectory()为 /Users/arthurwang/Library/Developer/CoreSimulator/Devices/3A7D67DC-0820-46BE-A567-53625AA03CD9/data/Containers/Data/Application/E31F52E0-E270-4707-8DD2-AC09EDE883F9。

// END 又一次了解了路径的处理。

相关文章

  • NSString+YYAdd的学习2

    看了NSString的API后才发现世界是那么的大大到一篇文章都写不下 路径扩展 NSPathUtilities....

  • NSString+YYAdd的学习

    NSString的内容好丰富啊,学习了很久很久,也补充了不熟悉的内容。 算法了解 Hash算法: 将任意长度的消息...

  • YYKit使用

    NSString+YYAdd 这个方法的作用就是返回给定的字符串边界的宽度和高度。这里size参数的意思是字符串的...

  • Dagger2学习笔记5(关于Lazy,Provide的使用)

    Dagger2学习笔记1(基础概念学习)Dagger2学习笔记2(学习Dagger2的简单使用)Dagger2学习...

  • Dagger2学习笔记4(@Singleton 与@ Scope

    Dagger2学习笔记1(基础概念学习)Dagger2学习笔记2(学习Dagger2的简单使用)Dagger2学习...

  • Dagger2学习笔记3(各个注解学习)

    Dagger2学习笔记1(基础概念学习)Dagger2学习笔记2(学习Dagger2的简单使用)上篇中学习了如何使...

  • Qt5学习地址

    Qt 学习之路 2(1):序(Qt 学习之路 2(1):序) Qt 学习之路 2(2):Qt 简介(Qt 学习之路...

  • 学习2

    块链和投资思考了 + 2在学习认知在做记录和写作,输出 + 3英语 — 焦虑感,是因为没有对时间的正确认识,当我们...

  • 学习2

    haofeng领导视角 自信 积极

  • 学习2

    我想我从未想过上大学后,还会熬夜。写那个入党申请书写了一个钟头,其实也不累,就是时间到一点多了!

网友评论

      本文标题:NSString+YYAdd的学习2

      本文链接:https://www.haomeiwen.com/subject/ngdrpxtx.html