Time of Update: 2015-07-16
標籤:學習來自《極客學院》1、定義方法需要在類型(枚舉,結構體,類)裡定義,不能獨立定義,獨立定義的是函數2、方法要麼屬於該類型本身,要麼是該類型的一個執行個體3、不能獨立執行方法,執行方法必須使用類型或執行個體作為調用者注意:枚舉、結構體中方法使用static修飾,類中用class修飾,都屬於類型方法,否則的話屬於執行個體方法 1 import Foundation 2 3 class SomeClass{ 4 func test(){ 5
Time of Update: 2015-07-15
標籤: 學習來自《極客學院:Swift中的函數》工具:Xcode6.4 直接上基礎的範例程式碼,多敲多體會就會有收穫:百看不如一敲,一敲就會 1 import Foundation 2 3 /***********嵌套函數*************/ 4 func getMathFunc(#type: String) -> (Int) -> Int{ 5 func squre(num:Int) -> Int{ 6 return
Time of Update: 2015-07-15
標籤:Swift中枚舉學習筆記來自《極客學院》 1 import Foundation 2 3 /**********1*Swift定義枚舉的文法格式*************/ 4 /* 5 enum 枚舉名 { 6 使用case關鍵字列出所有枚舉值 7 枚舉的其他成員 8 } 9 */10 //定義枚舉11 enum Season{12 case Spring13 case Summer14 case Fall15 case Winter16
Time of Update: 2015-07-14
標籤:學習來自《極客學院:Swift中的字串和集合》工具:Xcode6.4 直接上基礎的範例程式碼,多敲多體會就會有收穫:百看不如一敲,一敲就會 1 import Foundation 2 3 4 //數組:1、數組建立 2、訪問和修改數組 5 6 /*聲明數組寫法: 7 第一種:Array<SomeType>, 如Array<Int> 8 第二種:[SomeType],如[String] 9 */10 //第一種11 var myArr = Array&
Time of Update: 2015-07-15
標籤:學習來自《極客學院:Swift中的字典》工具:Xcode6.4 直接上基礎的範例程式碼,多敲多體會就會有收穫:百看不如一敲,一敲就會 1 import Foundation 2 3 //函數 4 /*1.定義函數的文法格式 5 func 函數名(形參列表) -> 傳回值類型 { 6 //可執行語句組成的函數 7 } 8 */ 9 //定義和調用函數10 func sayHello(personName: String) -> String{11
Time of Update: 2015-07-15
標籤:swift hello world 直接上代碼: // 輸出函數 println( "Hello world" ) // let 定義常量 var 定義變數 let loginCount = 5 var currentLoginCount = 0// loginCount = 10 // 爆紅// currentLoginCount
Time of Update: 2015-07-14
標籤:學習來自《極客學院:Swift中的字串和集合》工具:Xcode6.4 直接上基礎的範例程式碼,多敲多體會就會有收穫:百看不如一敲,一敲就會 1 import Foundation 2 3 4 /*******************字元********************/ 5 /* 6 1.單個字元來指定字元常量,如“A”、“9” 7
Time of Update: 2015-07-14
標籤://// ViewController2.swift// swift_helloword//// Created by Charlie on 15/7/13.// Copyright (c) 2015年 Json. All rights reserved.//import Foundationimport UIKitclass RootViewController:
Time of Update: 2015-07-13
標籤:ios swift首先我們來建立一個類吧,然後在裡面聲明屬性與方法 class BaseUser { var userName:String = "swh" var password:String = "123" //
Time of Update: 2015-07-11
標籤:os swift osx 最近在做一個好玩的OSX上的軟體,歡迎關注我微博哦http://weibo.com/u/2009667563/home?wvr=5&lf=reg本文在簡書的地址:http://www.jianshu.com/p/dedb26762055方法一:func applicationShouldHandleReopen(sender: NSApplication,
Time of Update: 2015-07-11
標籤:如下,一個UIContainerView內切換兩個Controller,當點擊登入的時候UIContainerView的視圖為LoginController,當點擊登記的時候UIContainerView中的視圖為RegisterController在主視圖內先做兩個按鈕的事件。這個不用說啦。當觸發按鈕事件的時候調用以下代碼就可以。var newController =
Time of Update: 2015-07-11
標籤:swift 拼圖 小遊戲 根據這位朋友的拼圖小遊戲改編 http://tangchaolizi.blog.51cto.com/3126463/1571616 改編主要地方是: 原本著我仁兄的代碼時支援拖動小圖塊來移動的,我參照之前自己java當初寫的,其實不需要拖動,因為只有一個空出來地方,那麼通過點擊事件,接受到點擊事件的小圖只能向一個方向移動或者不能移動。
Time of Update: 2015-07-10
標籤:ios swift uilabel 動態設定高度 import UIKitclass ViewController3: UIViewController { override func viewDidLoad()
Time of Update: 2015-07-10
標籤:ios swift Swift中類和對象的屬性分為三種:儲存屬性,計算屬性和類屬性。import Foundationclass Person { // 儲存屬性必須賦初值 var score1: Int = 20 var score2: Int = 50 // 延遲儲存屬性,需要時再去分配 lazy var dog: Dog = Dog() // 計算屬性,不能賦初值,提供get和set方法, var
Time of Update: 2015-07-10
標籤:swift 運算子 oc import Foundation//4、複合賦值操作符var a = 1a += 2//一元減運算子(一個數值前加了符號-,叫作一元減運算子)let three = 3let minusThree = -three //minusThree = -3let plusThree = -minusThree // plusThree =
Time of Update: 2015-07-10
標籤:switch enum string swift extension import Foundation//MARK:-------枚舉文法-----------//不像 C 和 Objective-C 一樣,Swift 的枚舉成員在被建立時不會被賦予一個預設的整數值enum CompassPoint{ case
Time of Update: 2015-07-10
標籤:/*1.swift字串和字元2.構造字串3.字串比較4.數值運算5.複製運算6.關係運算7.邏輯運算8.區間運算*//*//資料 + 資料的處理//字元資訊+ 字元資訊的處理//char a = ‘張‘//“hello”//const char * p = “hello”//char array[]= "hello"*///var c:Character//c = "張"////var b:String = "asdfa\0張/U0001f4
Time of Update: 2015-07-10
標籤://swift的廣義匹配let x = 1000switch x { case 1...9: println("個位元") case 1...9: println("十位元") default: println("其他")}let point = (10,10)switch point{case (0,0): println("0座標")case (1...10,1...10): println("x y一到十") case (_,0)
Time of Update: 2015-07-09
標籤: 在Swift中通過調用OC的CommonCrypto庫可以很方便的實現String字串轉換為sha1。 在一個swift項目中,需要使用橋接標頭檔(Bridging header)的方式來引入一個OC庫,才能調用OC中的內容。 本文也將作為Swift項目中如何調用Objective-C代碼的一個介紹。 標準實現步驟 1、建立一個Objective-C m檔案
Time of Update: 2015-07-10
標籤:ios swift uitableview import UIKitclass ViewController2: UIViewController,UITableViewDelegate,UITableViewDataSource{ override func viewDidLoad() { &