0% found this document useful (0 votes)
44 views57 pages

Native iOS Mobile App Development

The document provides a history of the iOS operating system developed by Apple Inc. for its mobile devices such as iPhone, iPad and iPod Touch. It discusses the major versions of iOS from the initial release in 2007 with iOS 1 to the latest iOS 14 in 2020. It describes the new features, upgrades and changes made in each iteration of iOS over the years that improved its functionality and expanded its capabilities.

Uploaded by

20521123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views57 pages

Native iOS Mobile App Development

The document provides a history of the iOS operating system developed by Apple Inc. for its mobile devices such as iPhone, iPad and iPod Touch. It discusses the major versions of iOS from the initial release in 2007 with iOS 1 to the latest iOS 14 in 2020. It describes the new features, upgrades and changes made in each iteration of iOS over the years that improved its functionality and expanded its capabilities.

Uploaded by

20521123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

LẬP TRÌNH TRÊN

THIẾT BỊ DI ĐỘNG

BUỔI 4
PHÁT TRIỂN ỨNG DỤNG DI
ĐỘNG NATIVE iOS

GVGD: ThS. Huỳnh Tuấn Anh


Outline

1. Introduction
● iOS History
● iOS and Ecosystem
2. iOS Architecture
3. iOS Application Development
4. Hello World
5. Objective C, Swift

2
History
• IOS or iPhone OS is a mobile operating system created
and developed by Apple Inc.
• Originally designed for the iPhone but now supports iPod
touch,iPad and Apple Tv
• Released on June 29, 2007
• It is updated just like Itune for iPods
• Written in C, C++, Objective-C, Swift, assembly language

First iOS logotype (2010–2013) Second iOS logotype (2013– Third iOS logotype (2017–present)
2017 3
History

• iOS 1: The birth of the iPhone (2007)


• iOS 2: App Store (2008)
• iOS 3: iPhone Enhancements (2009)
• IOS 4: Multitasking, Retina and Facetime (2010)
• IOS 5: Notification center, Siri & More (2011)
• IOS 6: Apple Maps & Passbook (2012)
• IOS 7: Wireless sharing feature Airdrop (2013)
• IOS 8: iCloud Drive (2014)
• iOS 9: 3D touch (2015)
• iOS 10: Facial Recognition (2016)
• iOS 11: Live Photos (2017)
• iOS 12: Emoji (2018)
• iOS 13: Dark Mode (2019)
• iOS 14: Widgets, App Library (2020)
4
History

Among the technological tribe, the most popular terms associated with mobile
phones are Android and iOS. While the former allows transparency and easy
accessibility, the latter has carved a mass for itself, even though it allows strict
connectivity. But when it comes to iPhones, the loyal customers forget all of its
cones and just stick on to the beauty, elegance and the magical iOS that runs like
a pure charm.
It was on June 29, 2007, Steve Jobs, the then chairman and co-founder of
[Link] launched iPhone with iOS 1. Since then, the operating system has
undergone some major upgrades, which was a result of continuous hard work and
passion towards achieving beyond the expectations of the consumer. Here, we are
glad to give you a brief sneak peek into the history of world’s favourite operating
system.
5
i O S1( i Phone O S 1)

The brainchild of Steve Jobs introduced the idea that an iPod, camera,
phone and internet device could be compacted inside a device that fits
in your pocket. At that time, iPhone was the actual star and other than
the technological geeks, no one was really interested in any information
about the operating system which made those phones work flawlessly.
iPhone OS 1, as it was named, was so special among the customers
as it was designed for multi-touch operation and a 3.5” capacitive
touchscreen, which made it quick and responsive than any other
present in the market then. While comparing it with the consecutive
versions of iOS, this version lacked huge including support for native,
third-party apps. But at the time of its launch, the phone and iOS 1
created a massive buzz among the elites and technologically inclined
lot.
iOS 2(i
Phone O S 2)

iPhone OS 2 released a year after, on July 2008


created a major breakthrough by adding App store,
which allowed the support of native, third- party apps.
More than 500 third-party apps were added on App
store during its launch, along with built-in 3G and
GPS technology. This gave smartphone market the
capacity to think limitless, which was visible from
Google’s move just after a month of iOS 2 launch-
android released Android Market, an older version of
Play Store.
iOS 3(i
Phone O S 3)

❖On June 2009, the next upgrade - iPhone OS 3- was not about
any dramatic inventions or transformations, but they focused on
fine-tuning the already developed programs. Jobs elevated the
whole iPhone using to the next level by adding push
notifications for third-party apps, parental controls, tap to focus
in the camera, in-app purchases and subscription models,
universal search with spotlight, and cut, copy, paste for the
touchscreen age.
❖Next January, iPad was launched with an updated version of
iOS 3 tailor-made
❖ just for the new model. iTunes was also upgraded by
adding options to buy movies, TV shows and books from
iPhone or iPod touch.
iOS 4(i
Phone O S 4)

Multitasking was the word of Apple in June 2010, when


they introduced iOS 4 enabling the user to switch
between the apps in a flash with a double press on the
home button. The feature loaded update had the name
iOS given to it, leaving behind the word “phone” from
the name of the operating system indicating its
compatibility with iPhones, iPods and iPads. FaceTime,
multitasking, iBooks, organizing apps into folders,
Personal Hotspot, AirPlay and AirPrint, some of the
current popular OS apps were introduced then.
i O S 5 ( i Phone O S5)

With the launch of iOS 5 in 2011, Apple was


beginning an era of virtual assistants. Yes,
Siri was added to iPhone in this version and
the whole world went crazy behind this
possibility of having a virtual assistant inside
your phone, that will actually obey your tasks
and even tell you jokes. Apple was also
getting ready to create new wave enemies in
future like Whatsapp, by introducing
iMessage and iCloud.
iOS 6 ( i Phone O S
6)
iOS 6, launched in 2012 witnessed a
major fail- the introduction of Apple maps as
a counter-attack on popular google [Link]
is marked as a mediocre step from the
stellar [Link], as it didn’t make any noise
even among Apple’s most loyal customers
or even inside Apple family. They also
removed Youtube from the pre-installed set
of apps. Some other added features include
a tighter integration with Facebook, a new
Passbook app and the iCloud allowing
shared photo streams.
iOS 7(i
Phone O S 7)

The world shouted “flat is beautiful” as the new


iPhone was released with an updated iOS 7. The
features included Contol Centre which meant quick
settings, iTunes radio service, multitasking for all
the apps, updated versions of Safari and Siri, and
finally Airdrop was introduced which enabled easy
connectivity and file transfer to other iPhones.
iOS 8 (i
Phone O S 8)
Again, in September 2014 Apple was in the mode
of fine-tuning the existing features. Firstly, they
brought together their desktops and mobile phones
closer by providing a continuity concept enabling
the user to send, edit and receive messages or
answer phone calls on both phones and Mac. They
opened up the platform wider by allowing third-
party widgets and keyboards for users to
customize their iPhone and introducing a
successful and secured payment option- Apple
pay. Also, iOS 8 engraved a new concept of
addiction- a health tracking app named health kit.
iOS 9 (i
Phone O S 9)

In September 2015, iOS 9 was unveiled.


Major transformation was that Siri got
way smarter- Apple named it Proactive
that is it brought back full panel spotlight
feature with intelligence. This version of
iOS felt like polishing every minute
detail to catch up with its equivalents.
Apps like notes, transit, Apple music
and news got a major fix, and 3D touch
was introduced.
iOS 10 ( i
Phone O S 10)
This time, the world witnessed a wide
opening up of Apple products to
third- party apps. Siri and iMessage
were redesigned to allow strong
third-party integration thus
connecting with Uber, Pinterest and
other popular names.
Apple also shared some love to their
users by filtering the photographs by
location, facial recognition and other
details, also automatically treasured
their precious moments together
into albums and video highlights.
i O S11( i Phone OS
11)

September 11, 2017, showed the world


what is going to be the future of
smartphones. Apple once again swept
the hearts of its users by changing the
look and feel of App store- a new
design and regular editorial content
helped users find apps more easily. All
the other major improvements were
targetted on iPad, the most important
ones being new files app and dock, a
novel concept for drag and drop
interactions and simpler multitasking.
i O S12 ( i Phone OS 12)

Apple announced iOS 12 on June 4, 2018, at its annual Apple Worldwide


Developers Conference (WWDC) event, and it was released to the public
on September 17, 2018, alongside the iPhone XS, iPhone XS Max and
iPhone XR.
With this release, Apple did not drop support for any iOS devices.
Therefore, iOS 12 was supported on the iPhone 5S onwards,
iPod Touch (6th generation), the iPad Air onwards, and the iPad Mini 2
onwards. However, iOS 12 has limited support on devices with the
Apple A7 or A8 processors: the iPhone 5S, iPhone 6/6 Plus,
iPod Touch (6th generation), iPad Air, iPad Air 2, iPad Mini 2, 3, and 4.
All other devices from the iPhone 6S/6S Plus onwards, the iPad Air (2019)
, the iPad (5th generation) onwards, and all iPad Pro models are fully
supported. iOS 12.1 bought support to the iPad Pro (12.9-inch, 3rd
generation) and iPad Pro (11-inch, 1st generation) and iOS 12.2 bought
support to the iPad Mini (5th generation) and iPad Air (3rd generation).
i O S13 ( i Phone OS 13)

Apple announced iOS 13 on June 3, 2019, at its annual Apple Worldwide


Developers Conference (WWDC) event, and it was released to the public on
September 19, 2019 alongside the iPhone 11 series (11, 11 Pro, 11 Pro Max). The
principal features include dark mode and Memoji support for A9+ devices. The NFC
framework now supports reading several types of contactless smartcards and tags.
[155]
The iPad gains several tablet-oriented features, and its operating system has
been rebranded as iPadOS; iPadOS 13 was announced at the 2019 WWDC as well.
With this release, Apple dropped support for all devices with less than 2 GB of RAM,
which included the iPhone 5S and iPhone 6 and 6 Plus, iPod Touch (6th generation)
, iPad Mini 2, iPad Mini 3, and iPad Air. iOS 13/iPadOS 13 has limited support on
devices with the A8/A8X or A9/A9X processors: the first-generation iPhone SE,
iPhone 6S/6S Plus, iPad Mini 4, iPad Air 2, iPad (5th generation), and
iPad Pro (1st generation). However, all other devices from the iPhone 7/7 Plus
onwards, iPod Touch (7th generation), iPad Pro (2nd generation),
iPad (6th generation), and iPad Mini (5th generation) onwards are fully supported.
iOS 13 brought support for the iPhone 11 and iPhone 11 Pro / Pro Max,
second-generation iPhone SE, and iPadOS 13 brought support for the
iPad (7th generation), the iPad Pro (12.9-inch, 4th generation) and the iPad Pro (11-
inch, 2nd generation).
i O S14 ( i Phone OS 14)

Apple announced iOS 14 and iPadOS 14 on June 22, 2020 at its annual WWDC 2020 event, with a
developer beta released on the same day and a public beta released on July 9, 2020. [162] iOS 14
and iPadOS 14 were released on September 16, 2020. All devices that supported iOS 13 also
support iOS 14. This makes the iPad Air 2 the first device to support seven versions of iOS and
iPadOS, from iOS 8 to iPadOS 14. Some new features introduced in iOS 14 and iPadOS 14
include redesigned widgets that can now be placed directly on the homescreen, along with the App
Library, which automatically categorizes apps into one page, Picture in Picture in iPhone and iPod
touch, and the CarKey technology to unlock and start a car with NFC. iOS and iPadOS 14 also
allow the user to have incoming calls shown in banners rather than taking up the whole screen (the
latter view is still available as an optional function).[163] iOS 14 and iPadOS 14 have limited support
on devices with an A8, A8X, A9 or A9X chip: the iPhone 6S, the iPhone 6S Plus, the first generation
iPhone SE, the iPad Air 2, the iPad Mini 4, the 5th generation iPad and the first generation iPad
Pros. Devices from the iPhone 7/7 Plus onwards, the iPod Touch (7th generation), the
iPad Pro (2nd generation), iPad (6th generation), iPad Air (3rd generation) and
iPad Mini (5th generation) onwards are fully supported.
i O S14 ( i Phone OS 14)

Apple announced iOS 14 and iPadOS 14 on June 22, 2020 at its annual WWDC 2020 event, with a
developer beta released on the same day and a public beta released on July 9, 2020. [162] iOS 14
and iPadOS 14 were released on September 16, 2020. All devices that supported iOS 13 also
support iOS 14. This makes the iPad Air 2 the first device to support seven versions of iOS and
iPadOS, from iOS 8 to iPadOS 14. Some new features introduced in iOS 14 and iPadOS 14
include redesigned widgets that can now be placed directly on the homescreen, along with the App
Library, which automatically categorizes apps into one page, Picture in Picture in iPhone and iPod
touch, and the CarKey technology to unlock and start a car with NFC. iOS and iPadOS 14 also
allow the user to have incoming calls shown in banners rather than taking up the whole screen (the
latter view is still available as an optional function).[163] iOS 14 and iPadOS 14 have limited support
on devices with an A8, A8X, A9 or A9X chip: the iPhone 6S, the iPhone 6S Plus, the first generation
iPhone SE, the iPad Air 2, the iPad Mini 4, the 5th generation iPad and the first generation iPad
Pros. Devices from the iPhone 7/7 Plus onwards, the iPod Touch (7th generation), the
iPad Pro (2nd generation), iPad (6th generation), iPad Air (3rd generation) and
iPad Mini (5th generation) onwards are fully supported.
iOS SDK

• iOS is Apple’s mobile operating system.


• Originally released for iPhone and iPod Touch, it has been
extended to support devices like iPad and Apple TV.
• Derived from OSX, with which it shares the Darwin
foundation and is therefore a UNIX-like operating system
by nature.
• Darwin is an open source POSIX compliant operating
system released by Apple Inc. in 2000.
• The user-interface of iOS is based on concept of direct
manipulation, using multi-touch gestures.
iOS SDK

• Unveiled with the iPhone at the MacWorld Conference & Expo,


January 9, 2007 and released in June, 2007.
• On March 6, 2008, Apple released the first beta of native Software
Development Kit (SDK), along with a new name for the operating
system : “iPhone OS”.
• In June, 2010, Apple rebranded iPhone OS as “iOS”.
iOS SDK
iOS SDK

• iPhone & iPod


• Display: 3.5in, 4in
• Resolution: 320x480(HVGA) at 163ppi, 640x960 at
326ppi, 1136x640
• Aspect Ratio: 2:3, 16:9
• Storage: 4GB, 8GB, 16GB, 32GB, 64GB
• Processor: 620MHz, 833MHz, 1GHz Apple A4, 1GHz
dual-core Apple A5, Apple A6, …
• Bus Frequency and width: 103MHz (32-bit), 100MHz
(32-bit), 100MHz (64-bit), 250MHz (64-bit)
• Memory: 128MB, 256MB, 512MB, 1GB, 2GB, 4GB, 6GB
• Devices: iPhone 3G, iPhone 3GS, iPhone 4, iPhone 4S,
iPhone 5, iPod Touch
Hardware
Hardware

• Proximity Sensor
deactivates the display and touchscreen when the
device is brought near the face during a call.
• 3-axis Accelerometer
senses the orientation of the phone and changes the
display accordingly.
• Ambient Light Sensor
adjusts the display brightness which in turn saves
battery power.
• Gyroscopic Sensor
enhances the perception of how the phone is
moved.
Platform Characteristics

• The Display is Paramount regardless of its size


• Device Orientation can change
• Apps Respond to Gestures, Not Clicks
• People Interact with One App at a Time
• Preferences are available in Settings
• Onscreen User Help Is Minimal
• Most iOS Apps Have a Single Window
• Two Types of Software Run in iOS
• iOS Apps
• Web Content

• Safari on iOS Provides the Web Interface


iOS Architecture
iOS Architecture

Working Process
Cocoa Touch Layer

• Auto Layout
• Storyboards
• Document Support
• Multitasking
• Printing
• UI State Preservation
• Apple Push Notification Service
• Local Notifications
• Gesture Recognizers
• Peer-to-Peer Services
• GameKit framework
• Standard System View Controllers
• UINavigatoinController, UITabBarController, UIPageView Controller
etc.
• External Display Support
Cocoa Touch Frameworks

• [Link]
• [Link]: calendar- based events
• [Link]
• [Link]
• [Link]
• [Link]
• [Link]
• [Link]
• Accelerometer data
• The built-in camera (where present)
• The user’s photo library
• Device name and model information
• Battery state information
• Proximity sensor information
Media Layer

• Graphics Technologies
• Core Graphics (Quartz)
• Core Animation
• Core Image
• OpenGL ES and GLKit
• Core Text
• Image I/O
• Assets Library framework
• Audio Technologies
• Media Layer framework
• AV Foundation framework
• Open AL
• Core Audio framework
• Supported file formats: AAC Protected (MP4), ALAC, A-law, IMA/ADPCM
(IMA4), Linear PCM, µ-law, DVI/Intel IMA ADPCM, Microsoft GSM 6.10,
AES3-2003
• Video Technologies
• UIImagePickerController
• Media Player framework
• AV Foundation framework
• Core Media
• Supported file formats: .mov, .mp4, .m4v, .3gp
• Compression Standards: H.264 video, up to 1.5Mbps, 640 by 480 pixels

H.264 video, up to 768Kbps, 320 by 240 pixels


MPEG-4 video, up to 2.5 Mbps, 640 by 480 pixels

• AirPlay: AirPlay is a technology that lets your application stream audio to Apple
TV and to third-party AirPlay speakers and receivers. Support is built-in in:
• AV Foundation framework
• Core Audio
Core Services Layer
• Frameworks
• High Level Features
• Accounts Framework
• iCloud Storage • Address Book Framework
• Automatic Reference • Ad Support Framework
Counting • CFNetwork Framework
• Core Data Framework
• Block Objects • Core Foundation Framework
• Data Protection • Core Location Framework
• Core Media Framework
• File-Sharing Support
• Core Motion Framework
• Grand Central Dispatch • Core Telephony Framework
• In-App Purchase • Event Kit Framework
• Foundation Framework
• SQLite • Newsstand Kit Framework
• XML Support • Pass Kit Framework
• Quick Look Framework
• Social Framework
• Store Kit Framework
• System Configuration
Framework
Core OS Layer

• Frameworks
• Accelerate Framework
• Core Bluetooth Framework
• External Accessory Framework
• Generic Security Services Framework
• Security Framework
• System
• LibSystem library
• Threading (POSIX threads)
• Networking (BSD sockets)
• File-system access
• Standard I/O
• Bonjour and DNS services
• Locale information
• Memory allocation
• Math computations
iOS SDK

Bước 1: Setup môi trường


Để phát triển các ứng dụng iPhone SDK và tiếp tục hướng dẫn này, bạn sẽ cần những điều sau
đây:
1. Trang bị máy tính Intel có hệ điều hành Mac OS X
2. Để viết các native application với iOS SDK và thử nghiệm các ứng dụng của bạn
trong iPhone chính thức của Apple hoặc Simulator iPad, bạn sẽ cần có hệ điều hành Snow
Leopard hoặc version cao hơn cài trên máy tính để bàn hoặc máy tính xách tay của Apple. Tuy
nhiên nếu bạn chỉ có máy tính chạy Windows thì cũng không phải quá lo lắng. Hãy đọc bài viết
sau đây để có thể cài đặt môi trường lập trình iOS trên máy tính chạy Windows.
3. Tạo một tài khoản Apple cho developer
4. Điều này là cần thiết để tải Xcode IDE, iOS SDK và iPhone Simulator. Bạn sẽ cần phải đăng ký
một tài khoản Apple cho Developer ở đây. Đăng ký là miễn phí và sẽ cho phép bạn chạy các ứng
dụng trong mô phỏng iPhone. Một tài khoản miễn phí là tất cả những gì cần thiết cho hướng dẫn
này, nhưng để thực sự chạy các ứng dụng của bạn trên một thiết bị hoặc công bố thông qua
Apple Store, bạn sẽ cần phải trả tiền để đăng ký trong iPhone Developer Program.
5. Cài đặt Xcode và iOS SDK
6. Sau khi đăng nhập vào tài khoản Apple Developer, bạn có thể tải về và cài đặt Xcode ...
và iPhone SDK … (hoặc phiên bản mới nhất – chú ý phải phù hợp với phiên bản MacOS X của
bạn).
iOS SDK
Bước 2: Khởi động Xcode và tạo project mới
Xcode là một môi trường phát triển tích hợp (IDE) kết hợp nhiều công cụ
cần thiết để xây dựng một chương trình vào một ứng dụng iPhone. Khởi
chạy Xcode bây giờ bằng cách tìm kiếm nó trong spotlight hoặc sử dụng
công cụ finder tìm đến đường dẫn cài đặt mặc định
của /Developer/Applications/Xcode.
Chọn “Create a new Xcode project” từ hộp thoại xuất hiện.
iOS SDK
Chọn Application dưới iOS ở cột bên trái. Trong danh mục Application
bạn sẽ thấy rất nhiều loại application. Tuy nhiên trong bài viết này chúng
tôi xin đề cử bạn chọn kiểu ứng dụng đơn giản nhất là “Single View
Application” và sau đó nhấn Choose.
iOS SDK

Tiếp tục, chúng ta nhấn vào nút Next và


sau đó khai báo các thông tin liên quan đến
project.
iOS SDK

Đặt tên project là HelloApple và tiếp tục


chọn một thư mục trên ổ cứng của bạn để
save project.
iOS SDK
Bước 3: Khởi động Interface Builder và tạo giao diện ứng dụng
Điều đầu tiên để bắt đầu cho việc tạo nên một giao diện cho ứng
dụng iPhone là bạn phải hiểu cấu trúc của project. Bạn hạy nhìn vào
project tree như hình bên dưới. Trong project tree có rất nhiều file và
loại file sẽ khác nhau một chút theo từng phiên bản của Xcode. Cụ thể
ở phiên bản Xcode 4.6 chúng tôi đang sử dụng thì để có thể sử dụng
bộ công cụ Interface Builder để thiết kế giao diện cho ứng dụng trên
iPhone thì xin mời bạn chọn và nhấn vào file
“[Link]“.
iOS SDK
Interface Builder là một công cụ đồ họa cho phép bạn nhanh chóng và
dễ dàng tạo ra layout cho các ứng dụng của bạn mà không cần viết một
dòng mã Objective-C nào cả. Như chúng ta sẽ thấy, nó cũng cho phép
bạn nhìn trực quan để xác định được mối quan hệ giữa các đối tượng
như buttons và methods mà bạn viết trong ứng dụng của bạn. Cụ thể
sau khi nhấn vào file storyboard thì giạo diện Interface Builder sẽ như
sau:
iOS SDK
iOS SDK
Công cụ Interface Builder gồm 3 phần chính mà bạn cần biết:
• View Controller
• View Controller cung cấp cho bạn cái nhìn trực quan ứng dụng của bạn trên một
màn hình thiết bị cụ thể. Bạn có thể kéo thả các GUI control trong thanh Libray
vào giao diện sau đó thiết lập các thuộc tính cũng như định dạng ở phần
Inspector.
• Library
• Thư viện hiển thị các đối tượng như buttons, labels, và textfields có sẵn để sử
dụng trong view của bạn. Các đối tượng có thể được tạo ra trong canvas của bạn
chỉ đơn giản bằng cách kéo chúng vào các view instance. Để mở thư viện,
chọn Tools> Libary từ thanh menu.
• Inspector
• Inspector cung cấp một cái nhìn chi tiết về các attributes và các connection giữa
các đối tượng của bạn. Mở cửa sổ Inspector bằng cách chọn Tools>
Inspector nếu nó chưa được mở. Lưu ý 4 thẻ tab ở phía trên cùng của cửa sổ
Inspector: attributes, connections, size và identity.
iOS SDK
Bây giờ chúng ta sẽ làm quen với Interface Builder thông qua một ví dụ nhỏ. Ở
trên phần Library, bạn chọn phần “Show Object Library“. Tiếp tục bạn sẽ nhìn thấy
danh sách các GUI control thông dụng. Ở ví dụ này tôi chi muốn các bạn làm một
thao tác đơn giả đó là tạo nên một giao diện với một label có dọng chữ “Hello
Apple“. Để làm điều đó, ở bên phần “Object Library“, bạn kéo label control
vào View Controller và thiết lập một số thuộc tính về font bên thanh Inspector>
Show the Attrtibutes inspector. Kết quả sẽ như hình bên dưới:
iOS SDK
iOS SDK
Đến bước này chắc các bạn rất nóng lòng muốn chạy ngay đúng không? Đừng vội, hãy chắc chắn rằng bạn đã
save tất cả công việc trong Interface Builder , sau đó chuyển về Xcode rồi nhấn nút Run để chạy ứng dụng của
bạn lại một lần nữa. Bây giờ bạn một thông điệp “Hello Apple” trên màn hình.
Objective-C
Ojective-C là ngôn ngữ lập trình hướng đối tượng thường được dùng để viết các
ứng dụng cho Mac OS X, iOS. Được thiết kế từ ngôn ngữ C bổ sung kiểu gọi
hàm của ngôn ngữ Smalltalk. Được phát triển vào đầu những năm 80 bởi công ty
NeXT (công ty của Steve Jobs khi ông rút lui khỏi Apple) Objective-C (obj-C) mở
rộng từ ngôn ngữ C cho nên những thuộc tính, đặc điểm định nghĩa khái niệm
của C nó đều có đủ.
Objective-C là ngôn ngữ lập trình như thế nào ? Hiểu một cách nôm na như mọi
người vấn nói đó là ngôn ngữ C được thêm vào phần hướng đối tượng.
Objective-C

Biên dịch nhanh và mềm mại: Bản thân trình biên dịch C cũng là huyền thoại tốc độ rồi
Obj-C còn được trang bị thêm nhiều đặc điểm ngôn ngữ uyển chuyển (Dynamic Script
Language) nữa. Ví dụ bạn có thể sử dụng kiểu tĩnh cho mọi biến nhưng những kiểu này lại
không bị xử ký quá cứng nhắc…
Tương thích với C và C++: Bạn có thể sử dụng, khai báo tất cả các kiểu dữ liệu của C, C++.
Trong thực tế có rất nhiều thư viện framework của Obj-C được viết bằng C, C++.
Tích hợp Cocoa: Cocoa được thiết kế cho Obj-C, đây là thư viện mạnh mẽ cho các ứng dụng
cảm ứng..
Swift

Sau 30 năm thống trị của Objective-C trên các nền tảng thuộc Apple, một thứ ngôn ngữ…
cồng kềnh và khó dùng không kém gì C++, Swift đã xuất hiện như một cứu cánh cho tất cả
những coder muốn dev iOS hay macOS.
Swift
Sau 30 năm thống trị của Objective-C trên các nền tảng thuộc Apple, một thứ ngôn ngữ…
cồng kềnh và khó dùng không kém gì C++, Swift đã xuất hiện như một cứu cánh cho tất cả
những coder muốn dev iOS hay macOS.
 Swift ra đời năm 2014, tính đến nay là 6 năm tuổi, nhưng đã có tới phiên bản thứ 5..,
cùng với việc open-source và xuất hiện trên Linux, chắc chắn Swift sẽ còn phát triển
nhanh hơn nữa
Tại sao Swift lại hot như vậy? Có thể kể đến các lý do sau:
 Là ngôn ngữ biên dịch, compiler optimize tốt => Nhanh (Swift chạy trên server
nhanh hơn hẳn NodeJS)
 Syntax là tổng hợp tinh hoa của các ngôn ngữ lập trình hiện đại => Dễ viết, viết đẹp
 Bắt buộc người code phải sử dụng thói quen tốt (good practice), có garbage collection,
compiler…=> An toàn, ít lỗi
 Tương thích tốt với Objective-C cũng như Cocoa Framework
 Open-source, liên tục được update, không còn chỉ giới hạn trong nền tảng của Apple
Swift
Swift

Vì là phát triển từ Objective-C, vốn là phát triển từ C nên cú pháp khá giống với các ngôn ngữ
họ C (C++, C#, Java,…). Có điều…
• Cuối câu lệnh không có chấm phẩy
• Bạn không phải include hay khai báo class gì cả, Hello World chỉ đơn giản là Hello World
• Khai báo biến có 2 từ khóa var và let. var là biến số, còn let là hằng số. Nếu giá trị khởi
tạo đủ rõ ràng thì không cần khai báo kiểu
• Swift cũng hỗ trợ Array (mặc định là mảng động), Dictionary (map trong C++) và Set
• In ra xâu ez hơn bao giờ hết, tạm biệt %, tạm biệt +
• If, for, while bắt buộc phải mở block (ngoặc nhọn í). Biểu thức của if, while bắt buộc trả về
giá trị kiểu Boolean
• Case trong switch tự động thoát sau khi kết thúc, không phải viết thêm một
dòng break cuối mỗi case nữa
• Switch không chỉ hỗ trợ so sánh bằng, bạn có thể sử dụng let-where để tạo điều kiện cho
case
Swift

Vậy là đã xong phần syntax. Cùng ngồi nghỉ một lúc và ngắm “Swift”
nào
Swift

Example

Hello World
// This program displays "Hello world!" // // References: // https:
//[Link]/library/content/documentation/Swift/Conceptual/
Swift_Programming_Language/Gui
[Link]

print("Hello world!")
Swift

// Declare our new class


class Person {
// We can define class property here
var age = 25
// Implement Class initializer. Initializers are called when a new object of this class is created
init() {
print(“A new instance of this class Person is created.”)
}
}

// We can now create an instance of class Person - an object - by putting parentheses after the class
name let personObj = Person()
// Once an instance of Person class is created we can access its properties using the dot “.” syntax.
print(“This person age is \([Link])”)
QUESTIONS?

57

You might also like