iOS 8 for Programmers: An App-Driven Approach with Swift (3rd Edition) (Deitel Developer Series) by Paul J. Deitel & Harvey M. Deitel & Abbey Deitel
Author:Paul J. Deitel & Harvey M. Deitel & Abbey Deitel
Language: eng
Format: azw3
Publisher: Pearson Education
Published: 2014-12-15T06:00:00+00:00
* * *
Fig. 5.16 | Model initializer and regionsChanged method.
Using NSBundle to Get Filenames
Recall that Foundation framework class NSBundle enables an app to access resources that are bundled with the app. Lines 52–53 obtain an Array of Strings containing the paths to all of the PNG images stored in the app’s main bundle. NSBundle method mainBundle returns the app’s main bundle. NSBundle method pathsForResourcesOfType returns an NSArray containing NSString representations of the paths for every file with the type specified by the first argument in the directory specified by the second argument. If the second argument is nil (as in line 53), pathsForResourcesOfType searches for all matching files in the app’s main bundle. We cast the returned NSArray of NSStrings to a Swift String Array—recall that this is allowed because the NSArray and NSString types are bridged to Swift’s Array and String types by the runtime. Next, lines 56–60 obtain the PNG image filenames from each path by using NSString property lastPathComponent. For each one, line 57 uses String method hasPrefix to determine whether that filename starts with "AppIcon"—the name Xcode gives to the app icons when you drag them onto the app’s asset catalog. Our app icons are also PNG images, so we add a filename to allCountries only if it does not start with "AppIcon". Finally, line 62 calls method regionsChanged to populate the countriesInEnabledRegions Array that’s used by the QuizViewController to select guesses to display with each flag.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Android | E-Readers |
Handheld & Mobile Devices | iPad |
iPhone | Programming & App Development |
Tablets |
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(6532)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6413)
Kotlin in Action by Dmitry Jemerov(5062)
Odoo 15 Development Essentials - Fifth Edition by Daniel Reis & Greg Mader(3340)
Odoo 15 Development Essentials by Daniel Reis(2814)
React Native - Building Mobile Apps with JavaScript by Novick Vladimir(2529)
Learning Angular - Second Edition by Christoffer Noring(2358)
Pride and Prejudice by Jane Austen(2350)
Mobile Forensics Cookbook by Igor Mikhaylov(2017)
Computers For Seniors For Dummies by Nancy C. Muir(1995)
Bulletproof Android: Practical Advice for Building Secure Apps (Developer's Library) by Godfrey Nolan(1872)
Android Development with Kotlin by Marcin Moskala & Igor Wojda(1797)
Building Android UIs with Custom Views by Raimon Ràfols Montané(1789)
1936941139 (N) by Bob Rosenthal(1731)
Building Progressive Web Apps: Bringing the Power of Native to the Browser by Ater Tal(1725)
Hands-On Internet of Things with MQTT by Tim Pulver(1706)
Android App Development by Franceschi Hervé J.;(1702)
Ember.js in Action by Joachim Haagen Skeie(1689)
Hands-On Design Patterns with React Native by Mateusz Grzesiukiewicz(1656)
