Frameworks & Modules

本文介绍了iOS应用开发中常用的UIKit、Foundation及CoreGraphics等框架的作用与特点,并探讨了Xcode5之后引入的模块化概念如何简化开发流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

UIKit

Cocoa classes that are specialized for iOS, whose names begin with “UI,” are part of the UIKit framework. The UIKit framework is imported (<UIKit/UIKit.h>) in the precompiled header file



Foundation

Many basic Cocoa classes, such as NSString and NSArray and others whose names begin with “NS,” are part of the Foundation framework. The Foundation framework is imported in the precompiled header file, but there is no need for this, because many headers imported by UIKit.h import the Foundation framework (<Foundation/Foundation.h>). In turn, Foundation.h includes the Core Foundation headers (<CoreFoundation/CoreFoundation.h>) and loads the Core Foundation framework as a subframework; thus, there is no need for you to import or link explicitly to the Core Foundation framework (which is full of functions and pointer types whose names begin with “CF,” such as CFStringRef).



Core Graphics

The Core Graphics framework defines many structs and functions connected with drawing, whose names begin with “CG.” It is imported by many UIKit headers, so you don’t need to import it explicitly.




Starting in Xcode 5 and LLVM 5.0, you can elect to make the process of using additional frameworks much simpler, by using modules

When you build an app that imports a framework header, if the information for that framework hasn’t been cached as a module, it is cached as a module at that moment. Here are some benefits of using modules:

1.  Smaller code files after precompilation

When you’re using modules, however, the imported header information lives in the modules, and the length of your code files is not significantly increased by precompilation. This might also mean that your code compiles faster.


2.  

Easier, shorter imports

#import <AddressBookUI/AddressBookUI.h>

With modules, instead of the #import directive, you can use a new directive, @import (with an at-sign instead of a hash-sign), which requires only the bare name of the framework followed by a semicolon:

@import AddressBookUI;

Moreover, #imports are automatically converted to @imports, so you can express yourself either way, and your existing code using #import keeps working while taking advantage of modules.


3.  

Autolinking

### 如何在Android项目中迁移并引用androidx库 #### 配置Gradle文件以支持AndroidX 为了确保项目能够顺利迁移到AndroidX,在项目的根目录下的`build.gradle`文件中,应当配置依赖项管理工具来应用必要的插件: ```groovy // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() mavenCentral() } dependencies { classpath &#39;com.android.tools.build:gradle:7.0.2&#39; // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() mavenCentral() } } ``` 对于模块级别的`build.gradle`文件,则需指定具体的依赖关系。这里展示了如何声明几个常见的AndroidX库作为实现级依赖[^1]。 ```groovy dependencies { implementation &quot;org.jetbrains.kotlin:kotlin-stdlib:1.8.10&quot; implementation &quot;androidx.core:core-ktx:1.9.0&quot; implementation &quot;androidx.appcompat:appcompat:1.6.1&quot; implementation &quot;androidx.constraintlayout:constraintlayout:2.1.4&quot; } ``` 请注意版本号的选择应基于最新的稳定版或是根据官方文档推荐的兼容组合来进行调整。 #### 使用Android Studio进行自动迁移 如果现有项目尚未采用AndroidX命名空间,可以借助IDE的力量简化这一过程。通过菜单栏中的`Refactor -&gt; Migrate to AndroidX...`选项启动向导,该功能会扫描整个工程并将旧的支持库替换为对应的AndroidX包名。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值