swift 第一个IOS应用程序

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

第一个IOS应用程序开发

一.准备工作:

(1)Mac OS X操作系统 10.9.3,

(2)Xcode6.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对象
參数为 这个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:.

? ? }

}

原文地址:https://www.cnblogs.com/mqxnongmin/p/10553767.html

时间: 2024-08-14 07:32:25

swift 第一个IOS应用程序的相关文章

使用Swift开始开发iOS应用程序

这是一篇面向IOS新手的初级文档.它提供一些信息帮助你采用技术和编程接口来开发苹果软件产品,不保证会在将来更新.学习它,需要你掌握一些基本的编程知识 1.至少熟悉或精通一门语言(最好是Java或C),因为你要学习一门新的语言(Swift),如果你之前没有学习过任何编程语言,这会让你学习起来非常困难. 2.最好有android基础(当然这不是必须的,但如果你学过android的话,对比学习IOS会非常效率) 3.一台苹果电脑(最好不要使用黑苹果了把) 本教程是新手学习IOS的最佳起点,他能让你创建

Xamarin iOS开发实战第1章使用C#编写第一个iOS应用程序

Xamarin iOS开发实战第1章使用C#编写第一个iOS应用程序 C#原本是用来编写Windows以及Windows Phone的应用程序.自从Xamarin问世后,C#的作用就发生了很大的变化.它不仅可以编写关于Windows以及Windowsx Phone的应用程序,还可以编写iOS.Android的应用程序.本章将讲解如何使用C#编写一个简单的iOS应用程序.本文选自<Xamarin iOS开发实战> 1.1初识Xamarin Xamarin是一个跨平台的开发框架.Xamarin的产

第一个iOS的程序,在界面上显示“Hello World”

1.如何新建一个工程 iOS->Single View Application->工程名.保存位置 2.运行App 点击三角符号或使用快捷键(Command + R) 快捷键:Command+B 只是编译,不是运行 3.工程的文件组成 4.应用程序是如何运行起来的? 1)main方法 int main(int argc, char* argv[])               {              @autoreleasepool {             return UIAppl

创建一个IOS应用程序

一.创建工程 二.Xcode中的IOS工程模板 一.Application: 1.Master-Detail:树形结构导航 2.Page-Base:电子书效果 3.Single-View: 4.Tabbed: 5.Game: 二.FrameWork & Library 三.应用分析 1.AppDelegate -->UIRespounder AppDelegate 应用程序委托对象,作为应用程序生命周期.状态保持.作用 2.ViewController --> UIViewContro

开发第一个IOS小程序 - 点击按钮文字变色

1. 题目:实现点击按钮切换文字对应的颜色 2.分析大致的开发步骤是 •添加所需要的UI元素:3个按钮(UIButton).1个文本标签(UILabel) •监听3个按钮的点击事件 •改变文本标签的文字颜色 3.具体实现步骤 3.1 在storyboard文件中,拖拽相应控件器上,布局好以上显示页面效果 3.2 然后利用Xcode右端上的“圆圈”按钮,将代码区分割成 “Main.storyboard”与“viewController.m”文件,两个可以按住control键,不要放开,将以上元素拖

[转载] iOS应用程序的生命周期

iOS应用程序的生命周期 2015-06-23 iOS大全 (点击上方蓝字,快速关注我们) iOS应用程序一般都是由自己编写的代码和系统框架(system frameworks)组成,系统框架提供一些基本infrastructure给所有app来运行,而你提供自己编写的代码来定制app的外观和行为.因此,了解iOS infrastructure和它们如何工作对编写app是很有帮助的. Main函数入口 所有基于C编写的app的入口都是main函数,但iOS应用程序有点不同.不同就是你不需要为iO

手把手教你写一个RN小程序!

时间过得真快,眨眼已经快3年了! 1.我的第一个App 还记得我14年初写的第一个iOS小程序,当时是给别人写的一个单机的相册,也是我开发的第一个完整的app,虽然功能挺少,但是耐不住心中的激动啊,现在我开始学react native,那么现在对于react native也算是有所了解了,就用网上的接口开发一个小程序,现在带大家来写这个程序!接口是用看知乎的API,简简单单的只有get,可以从这里入门,也算是带大家入门吧,过后我会把源代码放在我的github上,前期项目肯定特别简陋,后面慢慢来优

swift语言 编写 ios开发 第一个程序hello world!

老实说:第一个swift语句的ios不是代码敲出来的,我甚至还没来得急看代码,hello world 就出来了..... 本人开发环境:mac osx 10.10 dp1 + xcode6 beta + swift(更低xcode不支持swift语言) 思路与大致过程: 1.建立工程,工程包含界面文件,代码文件等等 2.在工程的界面文件中加入text控件,用于显示hello world 3.输入hello world ,模拟运行 让我们一步一步来: 1.建立工程,工程包含界面文件,代码文件等等

iOS游戏框架Sprite Kit基础教程第1章编写第一个Sprite Kit程序

iOS游戏框架Sprite Kit基础教程第1章编写第一个Sprite Kit程序 程序是为了实现特定目标或解决特定问题而用计算机语言编写的命令序列的集合.本章将以编写第一个Sprite Kit程序为主线,为开发者讲解什么是Sprite Kit.苹果账号的注册.Xcode的下载和安装.编写程序.调试等内容.选自iOS游戏框架Sprite Kit基础教程Swift版上册大学霸 1.1  Sprite Kit介绍 从iOS 7开始添加了Sprite Kit.本节将为开发者讲解什么是Sprite Ki