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),应用沙盒就是文件系统目录,并且与文件系统的其他部分隔 ...
随机推荐
- PL/SQL之存储过程和触发器实例
1.Oracle存储过程实例 /*不带任何参数存储过程(输出系统日期)*/ CREATE OR REPLACE PROCEDURE output_date IS BEGIN DBMS_OUTPUT.P ...
- synchronized同步锁
在多线程的情况下,由于同一进程的多个线程共享同一片存储空间,在带来方便的同时,也带来了访问冲突这个严重的问题.Java语言提供了专门机制以解决这种冲突,有效避免了同一个数据对象被多个线程同时访问.由于 ...
- Cheatsheet: 2017 07.01 ~ 07.31
Other 8 Key Application Performance Metrics & How to Measure Them The Code Review: The Most Impo ...
- Java集成groovy之GroovyShell、GroovyScriptEngine、GroovyClassLoader
GroovyClassLoader 用 Groovy 的 GroovyClassLoader ,动态地加载一个脚本并执行它的行为.GroovyClassLoader是一个定制的类装载器,负责解释加载J ...
- EMC光纤交换机故障处理和命令分析
主机没有Login到存储是一个比较常见的故障,故障多发于主机新上线,或者是重启后.例如在Unisphere中,显示Host状态是”Registered: Yes; Logged In: No” ...
- Spring_Spring与DAO_Spring的事务管理
一.Spring的事务管理 在Spring中通常可以通过以下三种方式来实现对事务的管理: 使用Spring的事务代理工厂管理事务 使用Spring的事务注解管理事务 使用AspectJ的AOP配置管理 ...
- 多项式乘法,FFT与NTT
多项式: 多项式?不会 多项式加法: 同类项系数相加: 多项式乘法: A*B=C $A=a_0x^0+a_1x^1+a_2x^2+...+a_ix^i+...+a_{n-1}x^{n-1}$ $B=b ...
- Mac里用终端ssh远程连接Centos服务器
在mac终端下输入 ssh -l root *.*.*.* 就可以远程连接Centos服务器了,端口没变还是:22 如果改变端口用下面方法输入: ssh -p 448(你改变的端口) -l root( ...
- 利用open live writer工具的Metaweblog技术API接口同步到多个博客。
测试例子内容: hello world hello metaweblog hello open live writer
- LintCode2016年8月22日算法比赛----克隆二叉树
克隆二叉树 题目描述 深度复制一个二叉树. 给定一个二叉树,返回一个它的克隆品. 样例 给定一个二叉树: 1 / \ 2 3 / \ 4 5 返回其相同结构相同数值的克隆二叉树: 1 / \ 2 3 ...