赞
踩
swift 出来也有一阵子了,一直没有时间来研究,简单的看了看,随手写几篇文章。特此声明:本博客纯属个人学习,有不足之处,属于正常,希望多多见谅.
第一个IOS应用程序开发
一.准备工作:
(1)Mac OS X操作系统 10.9.3,
(2)Xcode6.0,暂时我的Bt版本(有意外退出,和代码提示不全等现象)
二.本节涉及内容:
(1)变量和常量、函数、? !等符号的意义,简单的输出,IOS项目HellowroId
三.开始:
在这里就直接创建IOS项目了,在开发过程中遇到相关swift知识点在细谈,如图:
import UIKit
@UIApplicationMain
//class 在swift 中是声明一个类,在IOS项目中AppDelegate原来oc中的AppDelegate,应用程序的入口对象
class AppDelegate:UIResponder, UIApplicationDelegate
{
/*
var 声明变量关键字
window 是变量名
UIWindow 变量类型
? 可选类型在这里理解为空(nil)即可
*/
//声明一个全局变量
var window: UIWindow?
/*
关于swift 中变量和常量:
变量
var 声明变量关键字
var 声明没有类型,在变量的名字后面可以指定类型
如:
var i:Int = 3; // 声明一个int类型的变量,变量名字为 i变量的值为 3
常量:
let 常量声明关键字
let 声明没有类型,在变量的名字后面可以指定类型,常量的值是不可以改变的
如:
let d:Double =3.1415926;
d=3.5 //错误写法,因为常量的值是不可以改变的
*/
/*
函数:
swift 函数特点
(1)函数的参数中有标签(OC中的方法签名)
(2)函数的返回值在函数的尾部用指针符号(箭头)指向返回值类型
(3)函数声明关键字:func
*/
//第一个运行的入口函数,IOS生命周期那几个函数,可能会略有不同,你懂得,不懂后面说
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool
{
//UIWindow() 创建一个UIWindow对象 参数为 这个UIWindow的frame,下面我细说
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:.
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。