开发者社区> 问答> 正文

因为对OC的排斥以及接受不了[]的用法,所以我决定从Swift开始。后面的部分都是用swift语言学

因为对OC的排斥以及接受不了[]的用法,所以我决定从Swift开始。后面的部分都是用swift语言学!!!

展开
收起
刘刚_ 2020-05-15 16:09:08 854 0
1 条回答
写回答
取消 提交回答
  • 努力努力再努力

    使用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

    启动页面
    
    2020-05-15 16:12:07
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关课程

更多

相关电子书

更多
OpenStack Swift 海量小文件优化之路 立即下载
From Java/Android to Swift iOS 立即下载
Swift在Airbnb的应用实践 立即下载