因为对OC的排斥以及接受不了[]的用法,所以我决定从Swift开始。后面的部分都是用swift语言学!!!
使用swift新建一个ios工程,工程里面主要创建了几个文件,其实这几个文件在之前学OC的时候也简单知道了一些,但是在这里要系统的学习Swift了,所以还是要仔细再看看。 AppDelegate.swift
// 导入iOS中所有控件的库文件UIKit
import UIKit
// 调用了OC中的UIApplicationMain函数,它是iOS应用程序的入口,它会创建了一个UIApplication对象,
// 代表当前应用程序.作用是用来检测当前应用程序状态的改变,还会创建一个遵守UIApplicationDelegate的协议的子类对象作为UIApplication的代理,
// 作用是处理应用程序状态的改变(创建AppDelegate对象并且设置为UIApplication对象的代理)
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
// 类似Android中的PhoneWindow窗口
var window: UIWindow?
// 应用程序启动成功后,会自动调用到该方法
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
// 在这个方法中搭建应用程序界面、获取数据然后再展现,如果不在该方法中创建window,
//那么程序会通过Main.storyboard去创建应用程序界面
return true
}
// 将要变成非活跃状态时的回调(不可见),理解成Android中activity的生命周期
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
// 后台时调用
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
// 进入前台时
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
// 变成活跃状态
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
// 应用程序将要终止
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
ViewController.swift
import UIKit
class ViewController: UIViewController {
// 程序加载完成后的逻辑处理
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
}
Main.storyboard
类似Android中的xml文件等,可以写布局
Assets.xcassets
放图片等资源
LaunchScreen.storyboard
启动页面
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。