zoukankan      html  css  js  c++  java
  • swift 第一个IOS应用程序

    swift 出来也有一阵子了,一直没有时间来研究。简单的看了看。随手写几篇文章。特此声明:本博客纯属个人学习,有不足之处,属于正常,希望多多见谅.



    第一个IOS应用程序开发


    .准备工作:

    1Mac OS X操作系统 10.9.3

    2Xcode6.0,临时我的Bt版本号(有意外退出,和代码提示不全等现象)


    .本节涉及内容:

    1)变量和常量、函数、? !等符号的意义,简单的输出。IOS项目HellowroId


    .開始:

    在这里就直接创建IOS项目了,在开发过程中遇到相关swift知识点在细谈,如图:









    完毕

    打开AppDelegate.swift

    import UIKit


    @UIApplicationMain


    //class swift 中是声明一个类,在IOS项目中AppDelegate原来oc中的AppDelegate,应用程序的入口对象

    class AppDelegate:UIResponder, UIApplicationDelegate

     {

        

        

      /*

        var 声明变量keyword

        window 是变量名

        UIWindow 变量类型

        ?

    可选类型在这里理解为空(nil)就可以

       */

        //声明一个全局变量

       var window: UIWindow?

        

       /*

        关于swift 中变量和常量:

        变量

        var 声明变量keyword

        var 声明没有类型。在变量的名字后面能够指定类型

        如:

        var i:Int = 3; //  声明一个int类型的变量,变量名字为 i变量的值为 3

        

        常量:

        let 常量声明keyword

        let 声明没有类型,在变量的名字后面能够指定类型,常量的值是不能够改变的

        如:

        let d:Double =3.1415926;

        d=3.5  //错误写法,由于常量的值是不能够改变的

        */

        

       /*

        函数:

        swift 函数特点

        1)函数的參数中有标签(OC中的方法签名)

        2)函数的返回值在函数的尾部用指针符号(箭头)指向返回值类型

        3)函数声明keyword:func

        

        */

        

        //第一个执行的入口函数IOS生命周期那几个函数,可能会略有不同。你懂得,不懂后面说

       func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool

        {

            //UIWindow() 创建一个UIWindow对象 參数为 这个UIWindowframe,以下我细说

           self.window =UIWindow(frame: UIScreen.mainScreen().bounds)

            // Override point for customization after application launch.

            // ! 的意思是同意window==nil 时候执行。可是window==nil程序执行崩溃

            self.window!.makeKeyAndVisible()

            // 声明一个color 常量(color 是一个对象) UIColor 类调用redCorlor()类方法

           let color = UIColor.redColor();

            //设置self.window的背景颜色

           self.window!.backgroundColor = color;

           //输出

            println("Hellowrold IOS第一个项目");

           /*

            关于输出:

            swift 的输出用 println 

            输出一个字符串Hellowrold 

            println("Hellowrold");

            

            输出一个变量的值如:var f = 30.5

            var f = 30.5

            println("f=(f)");

            */

           return true

        }

     

        //下边以后在具体介绍

       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 throttle down OpenGL ES frame rates. 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 inactive 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:.

        }



    }





  • 相关阅读:
    tornado硬件管理系统-数据存储与表格实时监控(8)
    db2 内存研究
    Oracle dml开始到commit期间的流程
    用户界面与业务逻辑的分离
    计算器核心算法——终结版
    计算器核心算法——中缀表达式转为后缀表达式
    计算器核心解析算法(上)
    Qt中的字符串类
    初探Qt中的消息处理
    计算器界面代码重构
  • 原文地址:https://www.cnblogs.com/mqxnongmin/p/10553767.html
Copyright © 2011-2022 走看看