swift 第一个IOS应用程序
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 声明变量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对象
參数为 这个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:.
}
}
swift 第一个IOS应用程序的更多相关文章
- iOS 11开发教程(三)运行第一个iOS 11程序
iOS 11开发教程(三)运行第一个iOS 11程序 运行iOS11程序 创建好项目之后,就可以运行这个项目中的程序了.单击运行按钮,如果程序没有任何问题的话,会看到如图1.6和1.7的运行效果. 图 ...
- Xamarin iOS开发实战第1章使用C#编写第一个iOS应用程序
Xamarin iOS开发实战第1章使用C#编写第一个iOS应用程序 C#原本是用来编写Windows以及Windows Phone的应用程序.自从Xamarin问世后.C#的作用就发生了非常大的变化 ...
- Flutter 与 Swift - 在创建 iOS 应用程序时应该押注什么技术?
Swift 和 Flutter 是考虑创建 iOS 应用程序的公司最想要的两种技术.开发者能用原生技术取胜吗?如何选择,哪种更适合您的应用?让我们一探究竟吧! 根据 Statista 的数据, 201 ...
- 手把手教你写一个RN小程序!
时间过得真快,眨眼已经快3年了! 1.我的第一个App 还记得我14年初写的第一个iOS小程序,当时是给别人写的一个单机的相册,也是我开发的第一个完整的app,虽然功能挺少,但是耐不住心中的激动啊,现 ...
- [ios基础]IOS应用程序的生命周期问题
—程序的生命周期 a.程序的生命周期是指应用程序启动到应用程序结束整个阶段的全过程 b.每一个IOS应用程序都包含一个UIApplication对象,IOS系统通过该U ...
- iOS应用程序的生命周期
iOS应用程序一般都是由自己编写的代码和系统框架(system frameworks)组成,系统框架提供一些基本infrastructure给所有app来运行,而你提供自己编写的代码来定制app的外观 ...
- iOS 应用程序的生命周期
iOS 应用程序的生命周期(网络资源总结) http://blog.csdn.net/totogo2010/article/details/8048652 http://www.cocoachina. ...
- IOS应用程序生命周期&启动周期函数
—程序的生命周期 a.程序的生命周期是指应用程序启动到应用程序结束整个阶段的全过程 b.每一个IOS应用程序都包含一个UIApplication对象,IOS系统通过该U ...
- iOS/iPhone 程序文件目录结构以及启动流程
要想清晰的理解IOS应用程序的启动过程,毫无疑问需要深入了解一下ios应用程序的文件系统.一个ios应用程序都有一个属于自己沙盒(sandbox),应用沙盒就是文件系统目录,并且与文件系统的其他部分隔 ...
随机推荐
- webpack 报错 No PostCSS Config found 解决方案。
webpack 报错 No PostCSS Config found 这个问题我在百度上找了好久,也没有找到解决方案,最后没有办法只能自己去啃官方文档,本案例在本人的webpack 学习感悟中已经写 ...
- php中的namespace 命名空间
名字解释: namespace(命名空间),命名空间是从php5.3开始支持的功能.作用主要有两个:1.可以避免类名取得过长.2.当在多个框架配合使用时,同名的类之间不会冲突. 命名空间,看名字就知道 ...
- The following control could not be licensed: TXTextControl.TextControl。。解决方案
在这篇博客中,下面的控制不能授权:txtextcontrol.textcontrol这意味着,找不到合适的许可证来验证控制.一般情况下,许可证将被自动纳入应用程序,通常不必担心许可证的所有. “许可证 ...
- 图标插件FusionChartsFree
二.介绍 Ø FusionCharts 是InfoSoft Global 公司的一个产品,InfoSoft Global 公司是专业的Flash 图形方案提供商,他们还有几款其他的,基于Flash 技 ...
- java使用lock实现一个简单的生产者和消费者模式
import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; public ...
- fzou 1759 Super A^B mod C
Problem 1759 Super A^B mod CAccept: 456 Submit: 1488Time Limit: 1000 mSec Memory Limit : 32768 ...
- CNN中卷积过程中padding的使用
1.podding='SAME'时,全0填充. 2.padding=“VALID”,不使用全0填充
- 30个优秀的chrome网页设计开发插件
BuiltWith Resolution Test colorPicker Palette for Chrome Chrome Sniffer JS Library Detector Google F ...
- 实现键盘记录的e.Whick和keyCode,兼容FireFox和IE
主要分四个部分第一部分:浏览器的按键事件第二部分:兼容浏览器第三部分:代码实现和优化第四部分:总结 第一部分:浏览器的按键事件 用js实现键盘记录,要关注浏览器的三种按键事件类型,即keydown,k ...
- javascript实现数据结构: 树和森林
树的3种常用链表结构 1 双亲表示法(顺序存储结构) 优点:parent(tree, x)操作可以在常量时间内实现 缺点:求结点的孩子时需要遍历整个结构 用一组连续的存储空间来存储树的结点,同时在每个 ...