Learn Swift by Building Applications
Explore Swift programming through iOS app development
Emil Atanasov
- 366 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Learn Swift by Building Applications
Explore Swift programming through iOS app development
Emil Atanasov
About This Book
Start building your very own mobile apps with this comprehensive introduction to Swift and object-oriented programmingAbout This Book⢠A complete beginner's guide to Swift programming language⢠Understand core Swift programming concepts and techniques for creating popular iOS apps⢠Start your journey toward building mobile app development with this practical guideWho This Book Is ForThis book is for beginners who are new to Swift or may have some preliminary knowledge of Objective-C. If you are interested in learning and mastering Swift in Apple's ecosystem, namely mobile development, then this book is for you.What You Will Learn⢠Become a pro at iOS development by creating simple-to-complex iOS mobile applications⢠Master Playgrounds, a unique and intuitive approach to teaching Xcode⢠Tackle the basics, including variables, if clauses, functions, loops and structures, classes, and inheritance⢠Model real-world objects in Swift and have an in-depth understanding of the data structures used, along with OOP concepts and protocols⢠Use CocoaPods, an open source Swift package manager to ease your everyday developer requirements⢠Develop a wide range of apps, from a simple weather app to an Instagram-like social app⢠Get ahead in the industry by learning how to use third-party libraries efficiently in your appsIn DetailSwift Language is now more powerful than ever; it has introduced new ways to solve old problems and has gone on to become one of the fastest growing popular languages. It is now a de-facto choice for iOS developers and it powers most of the newly released and popular apps. This practical guide will help you to begin your journey with Swift programming through learning how to build iOS apps.You will learn all about basic variables, if clauses, functions, loops, and other core concepts; then structures, classes, and inheritance will be discussed. Next, you'll dive into developing a weather app that consumes data from the internet and presents information to the user. The final project is more complex, involving creating an Instagram like app that integrates different external libraries. The app also uses CocoaPods as its package dependency manager, to give you a cutting-edge tool to add to your skillset. By the end of the book, you will have learned how to model real-world apps in Swift.Style and approachThis book has a very practical and hands-on approach towards teaching the user the new and advanced features of Swift.
Frequently asked questions
Information
How to Use Data Structures, OOP, and Protocols
- Primary collection types
- List of items in a playground
- Table view in iOS app
- Protocols
Primary collection types
- Array: An ordered (indexed) list of values which are from the same data type
- Set: An unordered collection of unique values from the same data type
- Dictionary: An unordered collection map (key -> value), which links a key with a value, and the keys should be unique and from the same data type
Generics
struct Item<T> {
var raw: T
var description: String
init(raw: T, description:String = "no description") {
self.raw = raw
self.description = description
}
}
var itemInt:Item<Int> = Item(raw: 55, description: "fifty five")
print("This is an int \(itemInt.raw) with description - \(itemInt.description)")
var itemDouble:Item<Double> = Item(raw: 3.14, description: "Pi")
print("This is an int \(itemDouble.raw) with description - \(itemDouble.description)")
Array
var words = Array<String>(arrayLiteral: "one", "two", "three")
// short syntax using literals
//var words = ["one", "two", "three"]
for word in words {
print(word)
}
//empty array of int-s
var emptyArrayOfInts = [Int]()
//empty array of int-s
var emptyArrayOfInts2 = Array<Int>()
//the variable type is Array<Int> and the value is empty Array
var emptyArray:[Int] = []
var tenZeros = Array(repeating: 0, count: 10)
print("The number of items is \(tenZeros.count).")
var even = [2, 4, 6]
var odd = [1, 3 ,5]
var concatenated = even + odd
print(concatenated)
- .count: A property, which is read-only and returns the number of items in the concrete array instance
- .isEmpty: A property, which is read-only and returns true if, and only if, the array instance has no items
- .append(_:): A function which appends an item to the array instance (add the new item to the end of the list); an alternative option is to use the += operator
- .insert(_:at:): A function which inserts an item at a specific position in the array instance
- .remove(at:): A function which removes an item at the specific positions, but the position (index) should be correct; the removed item is returned
//the concatenated array contains [2, 4, 6, 1, 3, 5]
var part = concatenated[2...4]
print(part)
//prints [6, 1, 3]
for value in concatenated {
print("Item: \(value)")
}
for (index, value) in concatenated.enumerated() {
print("Item #\(index + 1): \(value)")
}