iOS Foundation 框架概述文档:常量、数据类型、框架、函数、发布声明

简介: iOS Foundation 框架概述文档:常量、数据类型、框架、函数、发布声明 太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循“署名-非商业用途-保持一致”创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作。

iOS Foundation 框架概述文档:常量、数据类型、框架、函数、发布声明

太阳火神的美丽人生 (http://blog.csdn.net/opengl_es)

本文遵循“署名-非商业用途-保持一致”创作公用协议

转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino否则,出自本博客的文章拒绝转载或再转载,谢谢合作。


Foundation 框架概述文档:常量、数据类型、框架、函数、发布声明
Title Topic Date
基础常量参考 Foundation Constants Reference A Content Update
基础数据类型参考 Foundation Data Types Reference A Minor Change
基础框架参考 Foundation Framework Reference A Content Update
基础函数参考 Foundation Functions Reference A Minor Change
Foundation Release Notes for iOS A First Version
Foundation Release Notes for OS X v10.9 A Content Update


1、基础常量参考 Foundation Constants Reference (以下仅选出常用的部分,完整列表可点击此行标题转入官网链接)

NSNotFound

定义一个值,用于指示请求项找不到或不存在。
Defines a value that indicates that an item requested couldn’t be found or doesn’t exist.

enum {
   NSNotFound = NSIntegerMax
};

NSEnumerationOptions

块枚举操作的选项。
Options for Block enumeration operations.

enum {
   NSEnumerationConcurrent = (1UL << 0),
   NSEnumerationReverse = (1UL << 1),
};
typedef NSUInteger NSEnumerationOptions;

NSComparisonResult

这些常量用于指示请求中的条目如何排序。
These constants are used to indicate how items in a request are ordered.

enum {
   NSOrderedAscending = -1,
   NSOrderedSame,
   NSOrderedDescending
};
typedef NSInteger NSComparisonResult;

NSSortOptions

块排序操作的选项。
Options for Block sorting operations.

enum {
   NSSortConcurrent = (1UL << 0),
   NSSortStable = (1UL << 4),
};
typedef NSUInteger NSSortOptions;

NSSearchPathDirectory

这些常量指定了各种目录位置,用于方法 URLsForDirectory:inDomains: 和 URLForDirectory:inDomain:appropriateForURL:create:error: NSFileManager 。
These constants specify the location of a variety of directories by the URLsForDirectory:inDomains: andURLForDirectory:inDomain:appropriateForURL:create:error: NSFileManager methods.

enum {
   NSApplicationDirectory = 1,
   NSDemoApplicationDirectory,
   NSDeveloperApplicationDirectory,
   NSAdminApplicationDirectory,
   NSLibraryDirectory,
   NSDeveloperDirectory,
   NSUserDirectory,
   NSDocumentationDirectory,
   NSDocumentDirectory,
   NSCoreServiceDirectory,
   NSAutosavedInformationDirectory = 11,
   NSDesktopDirectory = 12,
   NSCachesDirectory = 13,
   NSApplicationSupportDirectory = 14,
   NSDownloadsDirectory = 15,
   NSInputMethodsDirectory = 16,
   NSMoviesDirectory = 17,
   NSMusicDirectory = 18,
   NSPicturesDirectory = 19,
   NSPrinterDescriptionDirectory = 20,
   NSSharedPublicDirectory = 21,
   NSPreferencePanesDirectory = 22,
   NSItemReplacementDirectory = 99,
   NSAllApplicationsDirectory = 100,
   NSAllLibrariesDirectory = 101,
};
typedef NSUInteger NSSearchPathDirectory;

NSInteger and NSUInteger Maximum and Minimum Values

代表 NSInteger 和 NSUInteger 的最大值和最小值的常量。
Constants representing the maximum and minimum values of NSInteger and NSUInteger.

#define NSIntegerMax    LONG_MAX
#define NSIntegerMin    LONG_MIN
   
#define NSUIntegerMax   ULONG_MAX

2、 基础数据类型参考  Foundation Data Types Reference (以下仅选出常用的部分,完整列表可点击此行标题转入官网链接)

NSInteger

用于描述一个整型。(这个不是一个类,而是一个宏定义,是 C 长整型的别名)
Used to describe an integer.

typedef long NSInteger;

NSUInteger

用于描述一个无符号整型。(这个也不是一个类,而是一个宏定义,是 C 无符号长整型的别名)
Used to describe an unsigned integer.

typedef unsigned long NSUInteger;

NSTimeInterval

用于指定一个时间间隔,单位 秒。
Used to specify a time interval, in seconds.
以下这句原文,后半句关于毫秒部分的精度,没太明白,有懂得帮准确翻译一下,在此谢过。
NSTimeInterval is always specified in seconds; it yields sub-millisecond precision over a range of 10,000 years.

typedef double NSTimeInterval;

NSUncaughtExceptionHandler

用于处理异常处理域之外的异常。也即系统无法捕获的异常,配合 XCode 做异常跟踪很有用处。
Used for the function handling exceptions outside of an exception-handling domain.

typedef volatile void NSUncaughtExceptionHandler(NSException *exception);

NSSetUncaughtExceptionHandler

Changes the top-level error handler.

void NSSetUncaughtExceptionHandler (
   NSUncaughtExceptionHandler *
);
声明全局异常处理函数,它就是 NSUncaughtExceptionHandler *
 
        
void UncaughtExceptionHandler(NSException *exception) {
    
    // 获取异常相关信息
    NSArray *callStackSymbols = [exception callStackSymbols];
    NSString *callStackSymbolStr = [callStackSymbols componentsJoinedByString:@"\n"];
    NSString *reason = [exception reason];
    NSString *name = [exception name];
    
    // 获取系统当前时间
    NSDate * date = [NSDate date];
    NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init ];
    [dateFormatter setDateFormat:@"yyyy年MM月dd日 HH小时mm分ss秒"];
    NSString * dateStr = [dateFormatter stringFromDate:date];
    
    NSLog(@"系统当前时间为:%@ \n",dateStr);
    NSLog(@"异常名称:%@ \n",name);
    NSLog(@"异常原因:%@ \n",reason);
    NSLog(@"堆栈标志:%@ \n",callStackSymbolStr);
}
在应用适当初始化位置为系统设置该回调函数指针,AppDelegate 完成启动方法中比较适合:
 
        
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler);
    

NSStringEncoding

该类型代表字符串编码值。
Type representing string-encoding values.

typedef NSUInteger NSStringEncoding;

String Encodings

以下常量由 NSString 提供,作用可用的字符串编码。
The following constants are provided by NSString as possible string encodings.

enum {
   NSASCIIStringEncoding = 1,
   。。。
   NSUTF8StringEncoding = 4,
   。。。
   NSUnicodeStringEncoding = 10,
   。。。
   NSProprietaryStringEncoding = 65536
};
以上节选一部分常用的,从上面的链接,可以查看苹果官方文档完整部分。
但是,你会发现没有 GB2312、GBK 等编码,这个可以通过核心基础框架来解决,在基础框架中并未提供相应的编码。

CFStringConvertEncodingToNSStringEncoding

Returns the Cocoa encoding constant that maps most closely to a given Core Foundation encoding constant.

unsigned long CFStringConvertEncodingToNSStringEncoding (
   CFStringEncoding encoding
);

CFStringConvertNSStringEncodingToEncoding

Returns the Core Foundation encoding constant that is the closest mapping to a given Cocoa encoding.

CFStringEncoding CFStringConvertNSStringEncodingToEncoding (
   unsigned long encoding
);

CFStringEncoding

An integer type for constants used to specify supported string encodings in various CFString functions.

typedef UInt32 CFStringEncoding;

External String Encodings

CFStringEncoding 常量用于可能被 CFString 支持的编码。
CFStringEncoding
 constants for encodings that may be supported by CFString.

enum {
   。。。
   kCFStringEncodingGB_2312_80 = 0x0630,
   kCFStringEncodingGBK_95 = 0x0631,
   kCFStringEncodingGB_18030_2000 = 0x0632,
   。。。
   kCFStringEncodingBig5 = 0x0A03,
   。。。
   kCFStringEncodingHZ_GB_2312 = 0x0A05,
   。。。
};

kCFStringEncodingGB_18030_2000 是 GB 编码的最大集合,可以使用这个,用如下方式:
NSStringEncoding gbencoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);


3、基础框架参考  Foundation Framework Reference
这一部分是重点要掌握的,包括 基类 二进制类日期时区及本地化类、数值类、字符串类、字符集合类、枚举类、基本类型格式化及搜索类、集合类、错误与异常类、键值编码类、通知类、过滤和正则表达式类、XML 和 JSON 解析、撤销与重做、定时器类、线程同步类、线程安全类、线程通讯类、网络类、文件 之 偏好设置即用户默认设置类、文件 之 应用包及沙盒管理类、文件 之 归档与串行化类、文件 之 流类、蓝牙点对点通讯类、其它用得不多的少许类。

4、基础函数参考 Foundation Functions Reference

Assertions

For additional information about Assertions, see Assertions and Logging Programming Guide.

Bundles

For additional information on generating strings files see “Using Strings Files for User-Facing Text” in Internationalization Programming Topics.

Byte Ordering

Decimals

You can also use the class NSDecimalNumber for decimal arithmetic.

Exception Handling

You can find the following macros implemented in NSException.h. They are obsolete and should not be used. See Exception Programming Topics for information on how to handle exceptions.

Managing Object Allocation and Deallocation

Interacting with the Objective-C Runtime

Logging Output

Managing File Paths

Managing Ranges

Uncaught Exception Handlers

Whether there’s an uncaught exception handler function, any uncaught exceptions cause the program to terminate, unless the exception is raised during the posting of a notification.

Core Foundation ARC Integration

Managing Memory

Managing Zones

Zones are ignored on iOS and 64-bit runtime on OS X. You should not use zones in current development.












目录
相关文章
|
3月前
|
机器学习/深度学习 PyTorch TensorFlow
是否有其他框架可以在iOS设备上进行机器学习?
是否有其他框架可以在iOS设备上进行机器学习?
21 1
|
3月前
|
存储 数据建模 iOS开发
iOS设备功能和框架: 什么是 Core Data,它在 iOS 中的作用是什么?
iOS设备功能和框架: 什么是 Core Data,它在 iOS 中的作用是什么?
33 1
|
3月前
|
定位技术 iOS开发
iOS设备功能和框架: 如何使用 Core Location 获取设备的位置信息?
iOS设备功能和框架: 如何使用 Core Location 获取设备的位置信息?
19 0
|
3月前
|
存储 iOS开发 开发者
使用克魔助手进行iOS数据抓包和HTTP抓包的方法详解
使用克魔助手进行iOS数据抓包和HTTP抓包的方法详解
47 0
|
3月前
|
Web App开发 网络安全 Android开发
🚀2023最新版克魔助手抓包教程(9) - 克魔助手 IOS 数据抓包
在移动应用程序的开发中,了解应用程序的网络通信是至关重要的。数据抓包是一种很好的方法,可以让我们分析应用程序的网络请求和响应,了解应用程序的网络操作情况。克魔助手是一款非常强大的抓包工具,可以帮助我们在 Android 和 iOS 平台上进行数据抓包。本篇博客将介绍如何使用克魔助手在 iOS 平台上进行数据抓包。
|
3月前
|
机器学习/深度学习 PyTorch TensorFlow
iOS设备功能和框架: 什么是 Core ML?如何在应用中集成机器学习模型?
iOS设备功能和框架: 什么是 Core ML?如何在应用中集成机器学习模型?
27 0
|
3月前
|
iOS开发
iOS设备功能和框架: 如何使用 Core Animation 创建动画效果?
iOS设备功能和框架: 如何使用 Core Animation 创建动画效果?
101 0
|
5月前
|
小程序 开发工具 Android开发
Donut多端框架小程序打包适配ios和安卓app
腾讯新出了一个 Donut 多端框架,可以直接将微信小程序转成 ios 和 安卓 app,小程序开发者工具里也集成了 app 相关升级、调试和打包的功能,终于可以一套代码开发出3个客户端了!
127 0
Donut多端框架小程序打包适配ios和安卓app