FWWrapper

public struct FWWrapper<Base>

Swift包装器

  • 原始对象

    Declaration

    Swift

    public let base: Base
  • 初始化方法

    Declaration

    Swift

    public init(_ base: Base)

FWSafeValue

  • Undocumented

    Declaration

    Swift

    public var safeInt: Int { get }
  • Undocumented

    Declaration

    Swift

    public var safeBool: Bool { get }
  • Undocumented

    Declaration

    Swift

    public var safeFloat: Float { get }
  • Undocumented

    Declaration

    Swift

    public var safeDouble: Double { get }
  • Undocumented

    Declaration

    Swift

    public var safeString: String { get }
  • Undocumented

    Declaration

    Swift

    public var safeNumber: NSNumber { get }
  • Undocumented

    Declaration

    Swift

    public var safeArray: [Any] { get }
  • Undocumented

    Declaration

    Swift

    public var safeDictionary: [AnyHashable : Any] { get }

Available where Base == Data

  • Undocumented

    Declaration

    Swift

    public static func encoded<T>(_ value: T, using encoder: FWAnyEncoder = JSONEncoder()) throws -> Data where T : Encodable
  • Undocumented

    Declaration

    Swift

    public func decoded<T: Decodable>(as type: T.Type = T.self,
                                      using decoder: FWAnyDecoder = JSONDecoder()) throws -> T
  • Foundation对象编码为json数据

    Declaration

    Swift

    public static func jsonEncode(_ object: Any) -> Data?
  • json数据解码为Foundation对象

    Declaration

    Swift

    public var jsonDecode: Any? { get }
  • base64编码

    Declaration

    Swift

    public var base64Encode: Data { get }
  • base64解码

    Declaration

    Swift

    public var base64Decode: Data? { get }
  • 转换为UTF8字符串

    Declaration

    Swift

    public var utf8String: String? { get }

Available where Base == String

  • Foundation对象编码为json字符串

    Declaration

    Swift

    public static func jsonEncode(_ object: Any) -> String?
  • json字符串解码为Foundation对象

    Declaration

    Swift

    public var jsonDecode: Any? { get }
  • base64编码

    Declaration

    Swift

    public var base64Encode: String? { get }
  • base64解码

    Declaration

    Swift

    public var base64Decode: String? { get }
  • 计算长度,中文为1,英文为0.5,表情为2

    Declaration

    Swift

    public var unicodeLength: UInt { get }
  • 截取字符串,中文为1,英文为0.5,表情为2

    Declaration

    Swift

    public func unicodeSubstring(_ length: UInt) -> String
  • Unicode中文编码,将中文转换成Unicode字符串(如\u7E8C)

    Declaration

    Swift

    public var unicodeEncode: String { get }
  • Unicode中文解码,将Unicode字符串(如\u7E8C)转换成中文

    Declaration

    Swift

    public var unicodeDecode: String { get }
  • url参数编码,适用于query参数编码

    示例:http://test.com?id=我是中文 => http%3A%2F%2Ftest.com%3Fid%3D%E6%88%91%E6%98%AF%E4%B8%AD%E6%96%87

    Declaration

    Swift

    public var urlEncodeComponent: String? { get }
  • url参数解码,适用于query参数解码

    示例:http%3A%2F%2Ftest.com%3Fid%3D%E6%88%91%E6%98%AF%E4%B8%AD%E6%96%87 => http://test.com?id=我是中文

    Declaration

    Swift

    public var urlDecodeComponent: String? { get }
  • Declaration

    Swift

    public var urlEncode: String? { get }
  • Declaration

    Swift

    public var urlDecode: String? { get }
  • 字典编码为URL参数字符串

    Declaration

    Swift

    public static func queryEncode(_ dict: [String : Any]) -> String
  • URL参数字符串解码为字典,支持完整URL

    Declaration

    Swift

    public var queryDecode: [String : String] { get }
  • md5编码

    Declaration

    Swift

    public var md5Encode: String { get }
  • 文件md5编码

    Declaration

    Swift

    public var md5EncodeFile: String? { get }
  • 去掉首尾空白字符

    Declaration

    Swift

    public var trimString: String { get }
  • 首字母大写

    Declaration

    Swift

    public var ucfirstString: String { get }
  • 首字母小写

    Declaration

    Swift

    public var lcfirstString: String { get }
  • 驼峰转下划线

    Declaration

    Swift

    public var underlineString: String { get }
  • 下划线转驼峰

    Declaration

    Swift

    public var camelString: String { get }
  • 是否包含Emoji表情

    Declaration

    Swift

    public var containsEmoji: Bool { get }
  • 过滤JSON解码特殊字符

    兼容\uD800-\uDFFF引起JSON解码报错3840问题,不报错时无需调用 规则:只允许以\uD800-\uDBFF高位开头,紧跟\uDC00-\uDFFF低位;其他全不允许 参考:https://github.com/SBJson/SBJson/blob/trunk/Classes/SBJson5StreamTokeniser.m

    Declaration

    Swift

    public var escapeJson: String { get }
  • 转换为UTF8数据

    Declaration

    Swift

    public var utf8Data: Data? { get }
  • url

    转换为URL

    Declaration

    Swift

    public var url: URL? { get }
  • 转换为NSNumber

    Declaration

    Swift

    public var number: NSNumber? { get }
  • 从指定位置截取子串

    Declaration

    Swift

    public func substring(from index: Int) -> String
  • 截取子串到指定位置

    Declaration

    Swift

    public func substring(to index: Int) -> String
  • 截取指定范围的子串

    Declaration

    Swift

    public func substring(with range: NSRange) -> String
  • 截取指定范围的子串

    Declaration

    Swift

    public func substring(with range: Range<Int>) -> String

Available where Base == URL

  • 生成URL,中文自动URL编码

    Declaration

    Swift

    public static func url(string: String?) -> URL?
  • 生成URL,中文自动URL编码,支持基准URL

    Declaration

    Swift

    public static func url(string: String?, relativeTo baseURL: URL?) -> URL?
  • 获取当前query的参数字典,不含空值

    Declaration

    Swift

    public var queryDictionary: [String : String] { get }
  • 获取路径URI字符串,不含host|port等,包含path|query|fragment等

    Declaration

    Swift

    public var pathURI: String? { get }

Available where Base == String

  • 快速读取本地化语言

    Declaration

    Swift

    public var localized: String { get }
  • 快速读取本地化语言,指定Bundle

    Declaration

    Swift

    public func localized(_ bundle: Bundle?) -> String

    Parameters

    bundle

    语言所在Bundle,默认主Bundle

    Return Value

    本地化字符串

  • 快速读取本地化语言,指定表名和Bundle

    Declaration

    Swift

    public func localized(_ table: String?, _ bundle: Bundle? = nil) -> String

    Parameters

    table

    本地化表名,默认Localizable.strings

    bundle

    语言所在Bundle,默认主Bundle

    Return Value

    本地化字符串

Available where Base == Data

  • 使用NSKeyedArchiver压缩对象

    Declaration

    Swift

    public static func archiveObject(_ object: Any) -> Data?
  • 使用NSKeyedUnarchiver解压数据

    Declaration

    Swift

    public func unarchiveObject<T>(_ clazz: T.Type) -> T? where T : NSObject, T : NSCoding
  • 保存对象归档

    Declaration

    Swift

    public static func archiveObject(_ object: Any, file: String) -> Bool
  • 读取对象归档

    Declaration

    Swift

    public static func unarchiveObject<T>(_ clazz: T.Type, file: String) -> T? where T : NSObject, T : NSCoding

Available where Base == Date

  • 当前时间戳,没有设置过返回本地时间戳,可同步设置服务器时间戳,同步后调整手机时间不影响

    Declaration

    Swift

    public static var currentTime: TimeInterval { get }
  • 从字符串初始化日期,自定义格式(默认yyyy-MM-dd HH:mm:ss)和时区(默认当前时区)

    Declaration

    Swift

    public static func date(string: String, format: String = "yyyy-MM-dd HH:mm:ss", timeZone: TimeZone? = nil) -> Date?
  • 转化为字符串,默认当前时区,格式:yyyy-MM-dd HH:mm:ss

    Declaration

    Swift

    public var stringValue: String { get }
  • 转化为字符串,自定义格式和时区

    Declaration

    Swift

    public func string(format: String, timeZone: TimeZone? = nil) -> String
  • 格式化时长,格式"00:00"或"00:00:00"

    Declaration

    Swift

    public static func formatDuration(_ duration: TimeInterval, hasHour: Bool) -> String

Available where Base == String

  • 计算多行字符串指定字体、指定属性在指定绘制区域内所占尺寸

    Declaration

    Swift

    public func size(font: UIFont, drawSize: CGSize = CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude), attributes: [NSAttributedString.Key : Any]? = nil) -> CGSize
  • 格式化文件大小为".0K/.1M/.1G"

    Declaration

    Swift

    public static func sizeString(_ aFileSize: UInt) -> String
  • 是否匹配正则表达式,示例:^[a-zA-Z0-9_\u4e00-\u9fa5]{4,14}$

    Declaration

    Swift

    public func matchesRegex(_ regex: String) -> Bool