BeginningDeveloperFeaturediOS DeveloperNewbieProgramming LanguageSwift

เขียนแอพ iPhone บน iOS8 ภาษา Swift ด้วย Xcode6 BETA

มารีวิว Xcode 6 BETA กันหน่อยกับภาษา Swift ว่ามีอะไรน่าสนใจผ่านฟังก์ชันสุดฮิต Hello World และภาษา Swift เบื้องต้นที่จำเป็นทั้งหลาย

Screen Shot 2557-06-11 at 8.24.39 PM

หลังจากที่ Apple ปล่อยตัว Xcode6 BETA และภาษา Swift มาให้ลองศึกษากัน ผมก็ไม่ค่อยมีเวลามากนักในการทดสอบ เพราะติดโปรเจ็คมากมายหลายสิ่ง วันนี้นัดเพื่อนที่อยากจะลองทดสอบ iOS8 กันก็เลยได้โอกาสเทส ภาษา Swift และเจ้า Xcode 6 ไปด้วยเลย

ฟังก์ชันทุกอย่างก็อยู่ครบครับ หากลองเลือก 2 แบบคือ Single Application และ เขียนเกมผ่าน Sprite Kit ก็จะเห็นความแตกต่างเล็กน้อยดังนี้

Screen Shot 2557-06-11 at 8.02.17 PM

สำหรับ Single Application จะมีให้เลือกไม่ต่างจากเดิม

Screen Shot 2557-06-11 at 8.02.30 PM

 

บน Sprite Kit

Screen Shot 2557-06-11 at 7.56.00 PM

สำหรับ Sprite Kit ก็เลือกได้ว่าจะพัฒนาด้วย ภาษาอะไร ทั้ง Objective-C และ Swift ซึ่งผมก็ต้องเลือก Swift ครับ

หน้า MainStoryBoard ก็รองรับเรื่องของ Auto Layout ที่แสนปวดหัวได้อย่างดี

Screen Shot 2557-06-11 at 8.03.35 PM

กลับมาที่ Single Application ก่อนครับ มาลองทำ Hello worlds กัน
ก็เปิดไปที่ไฟล์ ViewController.swift เลยครับ

หา เมธอด ViewDidLoad() แล้วก็เพิ่มคำสั่งยอดฮิตเข้าไปครับ คลาสทั้งหมดจะเป็นแบบนี้

import UIKit

class ViewController: UIViewController {
                            
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        println("Hello World")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

ลองทำการ Run คำสั่งกันหน่อยสิว่า มัน Work ไหม?

Screen Shot 2557-06-11 at 8.07.44 PM
ก็ใช้ได้ครับ เอาเป็นว่าเป็นการเริ่มต้นที่ง่ายๆ สบายๆ เดี๋ยวจะอัพบทความเพิ่มให้เรื่อยๆ ตามเวลาว่างครับ

Asst. Prof. Banyapon Poolsawas

อาจารย์ประจำสาขาวิชาการออกแบบเชิงโต้ตอบ และการพัฒนาเกม วิทยาลัยครีเอทีฟดีไซน์ & เอ็นเตอร์เทนเมนต์เทคโนโลยี มหาวิทยาลัยธุรกิจบัณฑิตย์ ผู้ก่อตั้ง บริษัท Daydev Co., Ltd, (เดย์เดฟ จำกัด)

Related Articles

Back to top button
Game & Mobile Development AR VR XR
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

Adblock Detected

เราตรวจพบว่าคุณใช้ Adblock บนบราวเซอร์ของคุณ,กรุณาปิดระบบ Adblock ก่อนเข้าอ่าน Content ของเรานะครับ, ถือว่าช่วยเหลือกัน