Monday, December 04, 2017

iOS 11 New Feature: Displaying Large Size Content

iOS 11 introduce many great features. One of them is display large size content, for example, text and images. With small size of mobile devices, for many people it is really hard to read small text or content. With this new feature in iOS 11, I want to support it in my app.

One new change is the large size title in navigation control. Another one is dynamic size for text views. PDF format for images is also great to avoid making various size of images in project.

There are two very good videos to watch as in the reference.

References


Read More...

Monday, November 13, 2017

Dynamic Height of TableView Cell

For table view in iOS, its cell could be one of several styles: basic, detail, subtitle and custom. The first 3 are built-in style. The title, subtitle, and detail are labels in the cell. By default, those labels cannot grow vertically if text in the label is too long. I found out there is a property for label to control if displaying only one or multiple lines: numberOfLines. By default, this property is one.

If you change the property to 0, the label may grow vertically to show all the text in it. That means the view cell in a table view could grow dynamically in height. This is true for the first three styles. However, for the custom view cell, it is tricky.

Recently, I was working on my iOS app to enhance its user interface. One of table views contains custom view cell. I would like to show cells in dynamic height if labels in the cell having long text. At first, I tried to set up enough constrains in the custom view cell so that no any warning nor errors in storyboard. However, my view could not show dynamic cell height.



It seems that all cell height are the same.

Finally I figured out why. The contrails in the custom view cell have to be enough for UIKit to calculate the height. In my view, I placed three labels one by one vertically. From top to bottom, I set constrains one to next vertically. However, I did not add a constrain from the last label to the bottom. As a result, UIKit could get the height of view cell.



I added the constrain to make sure the last label's bottom related to the bottom of its container. With this change, I got my app working as expected.




Enough-constrains-for-vertial-span is a trick for custom table view cell. There are other things which have to be set for dynamic cell height. See the reference blog for detail.

By the way, my app supports several languages. Therefore, for this update, I have to make all the changes in all language views in storyboard. You may notice that the messy one above is in Chinese, and the next expected one is in English. By the time I am writing this blog, I have not updated my Chinese view yet.

Reference


Read More...

Wednesday, November 08, 2017

Grey blank toolbar on TableView

During my work on my iOS app (TapToCount - 3W), I had a very bizarre issue. There is grey blank toolbar appearing above tab bar on one of tableview controller.

Problem


Actually, the main view with tableview looks OK initially. A grey blank tool bar appears above tab bar after back from a detail view.



The detail view is popped up from the main view when a row of tableview is selected by using navigation controller. The detail view shows a toolbar with some buttons, but no tab bar. Look at detail view, I notice that the tool bar actually is raised up from bottom.




I tried to find what settings triggered this problem from storyboard on both main and detail views, as well as my codes for those views. I could not find anything wrong.

One thing I noticed is that the English version runs good. The problem only appeared on my Chinese version (when I changed iOS language to simplified Chinese, but traditional Chinese is good). I think that it must be something I might changed in storyboard for simplified Chinese. Most unlikely in my view controller codes.

Snapshots to Find out Differences


I am using MaBook Air 2014 on my App. There are tens of property settings in a view. It is really very painful slow (about 40 secs) to compare those settings switch back and forth between Chinese and English storyboards. I found a trick to do the checking, taking snapshots of property settings in one language and then using those snapshots to compare property settings in another language.

Interesting thing is that both main and detail views are exactly same! That puzzled me. Soon I realize that the view is driven by navigation controller. There might be something different in navigation controller. There are several navigation controllers: root view controller (tab view controller as start), master view controller (split view controller), and navigation controller.

From those view controllers, I found the differences!







I am not sure what those marked settings mean. I changed the settings in views of Chinese storyboard. voilĂ ! It works!

Here is the current version of views for the same problem ones as in above.






Conclusion


Sometimes, it may be hard to find out straight solutions either from my own knowledge/skills or internet. There may be some other ways to target the issue. Here is an example, from working version as start, then trace down the difference in the problem target.

I am not going to explain what caused the problem. I may figure out reason behind those property settings. This blog is just a note about my programming experience and growth.

Read More...

Monday, October 02, 2017

Container View Pushed Down in Navigation View

After I transferred my codes from Swift 3.0 to 4.0 in Xcode 9.0, I noticed that one of view's content is pushed down about the height of navigation bar. Before my app was working fine.

After hours investigation I still had no clue. Then I searched from Internet. Soon I found one solution. It is not obviously related my conversion. It is just the navigation bar in the previous navigation controller has to be set Translucent! With that change my views in all localization back to normal. Love StackOverflow and solution offered by developers!

Reference






Read More...

Monday, September 18, 2017

My First iOS App is Released!

Today is important date, Sept 18, 2017 Monday, for me. My first iOS app: TapToCount - 3W is released on the App Store!

I submitted my app last Friday and I got several email notifications about the app status. After I completed all the required information submission, the app is released on the App Store. That's approval process is a surprise for me.

The app is universal one, i.e., for iPhone and iPad. However, I have not got screenshots for iPad yet, so the current app is only for iPhone. I hope I'll get it ready for iPad soon.

Currently the first version is available at US, Canada, British and Australia, English speaking countries. The app does support Chinese, bot Simplified and Traditional ones. I am in the process of preparing screen shots for Chinese stores.

References


Read More...

Friday, September 15, 2017

Change Blogger's Theme

Recently I created a new blog for my iOS app: TapToCount - 3W.

For this web blog, I choose a theme from blog settings. The layout looks fine, except the main page displays an image from my first blog as background image at the top. It stretches ugly taking a lot of spaces on the top.

I need to disable this from the theme. After exploration on the theme's html codes, I found a simple way to disable it.



As marked in red box, I changed the variable "hasImage" to "hasImages". This minor change of variable name makes the block of html codes not embedded into the main page.

This is a note about what I did. Otherwise, I may forget what I did in the blog's theme.

References


My new blog: TapToCount - 3W

Read More...

Thursday, August 17, 2017

WWDC 2017 Vedios

WWDC 2017 is over (Jun 5-9, 2017). As I did in the past years, I finally finished watching all videos of WWDC 2017 provided by Apple. There are 136 videos (49+19+15+5+4+10+15+19), each ranging from 10 minutes to over 2 hours, most around 30+ minutes. So I guess the total length of the video is about 70 hours.

Here is the list of videos I watched:

WWDC 2017

Platforms State of the Union - 102
Introducing Core ML - 703
Introducing ARKit: Augmented Reality for iOS - 602
Introducing Metal 2 - 601
Introducing Drag and Drop - 203
What's New in Swift - 402

App Frameworks

  1. Advanced Animations with UIKit - 230
  2. Advanced Touch Bar - session 222
  3. Advances in TVMLKit - 202
  4. Build Better Apps with CloudKit Dashboard - 226
  5. Building Apps with Dynamic Type - 245
  6. Building Great Document-based Apps in iOS 11 - 229
  7. Building Visually Rich User Experiences - 235
  8. Choosing the Right Cocoa Container View - 218
  9. Cocoa Development Tips - 236
  10. Connecting CareKit to the Cloud - 239
  11. Customized Loading in WKWebView - 220
  12. Data Delivery with Drag and Drop - 227
  13. Deep Linking on tvOS - 246
  14. Drag and Drop with Collection and Table View - 223
  15. Efficient Interactions with Frameworks - 244
  16. Extend Your App's Presence With Sharing - 247
  17. Extend Your App’s Presence with Deep Linking - 250
  18. File Provider Enhancements - 243
  19. Filtering Unwanted Messages with Identity Lookup - 249
  20. Focus Interaction in tvOS 11 - 224
  21. Introducing Business Chat - 240
  22. Introducing PDFKit on iOS - 241
  23. Introducing Password AutoFill for Apps - 206
  24. Localization Best Practices on tvOS - 248
  25. Making Great SiriKit Experiences - 228
  26. Mastering Drag and Drop - 213
  27. Media and Gaming Accessibility - 217
  28. Modern User Interaction on iOS - 219
  29. Natural Language Processing and your Apps - 208
  30. Now Playing and Remote Commands on tvOS - 251
  31. The Keys to a Better Text Input Experience - 242
  32. The Life of a watchOS App - 216
  33. Touch Bar Fundamentals - 211
  34. Updating Your App for iOS 11 - 204
  35. What's New in Accessibility - 215
  36. What's New in CareKit and ResearchKit - 232
  37. What's New in Cocoa - 207
  38. What's New in Cocoa Touch - 201
  39. What's New in Core Data 210
  40. What's New in Core Spotlight for iOS and macOS - 231
  41. What's New in Foundation - 212
  42. What's New in Health - 221
  43. What's New in MapKit - 237
  44. What's New in Safari View Controller - 225
  45. What's New in SiriKit - 214
  46. What's New in iMessage Apps - 234
  47. What's New in tvOS - 209
  48. What's New in watchOS 205
  49. Writing Energy Efficient Apps - 238
Design
  1. 60 Second Prototyping - 818
  2. App Icon Design - 822
  3. Communication Between Designers and Engineers - 809
  4. Design Tips for Great Games - 811
  5. Designing Across Platforms - 804
  6. Designing Glyphs - 823
  7. Designing Sound - 803
  8. Designing for Subscription Success - 814
  9. Designing for a Global Audience - 819
  10. Essential Design Principles - 802
  11. Express Yourself! - 820
  12. Get Started with Display P3 - 821
  13. How to Pick a Custom Font - 815
  14. Love at First Launch - 816
  15. Planning a Great Apple Watch Experience - 808
  16. Rich Notifications - 817
  17. Size Classes and Core Components - 812
  18. What’s New in iOS 11 - 810
  19. Writing Great Alerts - 813
Developer Tools
  1. App Startup Time: Past, Present, and Future - 413
  2. Auto Layout Techniques in Interface Builder - 412 very nice on storyboard layout!
  3. Debugging with Xcode 9 - 404
  4. Engineering for Testability - 414
  5. Finding Bugs Using Xcode Runtime Tools - 406
  6. GitHub and the New Source Control Workflows in Xcode 9 - 405
  7. Localizing Content for Swift Playgrounds - 410
  8. Localizing with Xcode 9 - 401
  9. Teaching with Swift Playgrounds - 416
  10. Understanding Undefined Behavior - 407
  11. What's New in LLVM - 411
  12. What's New in Signing for Xcode and Xcode Server - 403
  13. What's New in Swift - 402
  14. What's New in Testing - 409
  15. What’s New in Swift Playgrounds - 408
Distribution
  1. Advanced StoreKit - 305
  2. Introducing the New App Store - 301
  3. What's New in Device Configuration, Deployment, and Management - 304
  4. What's New in StoreKit - 303
  5. What's New in iTunes Connect - 302
Featured
  1. Convenience for You is Independence for Me - 110
  2. From Monroe to NASA - 106 - NA yet
  3. Platforms State of the Union - 102
  4. WWDC 2017 Keynote - 101
Graphics and Games
  1. From Art to Engine with Model I/O -610
  2. Going Beyond 2D with SpriteKit - 609
  3. Introducing ARKit: Augmented Reality for iOS - 602
  4. Introducing Metal 2 - 601
  5. Metal 2 Optimization and Debugging - 607
  6. SceneKit in Swift Playgrounds - 605
  7. SceneKit: What's New - 604
  8. Using Metal 2 for Compute - 608
  9. VR with Metal 2 - 603
  10. What's New with Screen Recording and Live Broadcast - 606
Media
  1. Advances in Core Image: Filters, Metal, Vision, and More -510
  2. Advances in HTTP Live Streaming - 504
  3. Apple Podcasts - 512
  4. Capturing Depth in iPhone Photography - 507
  5. Error Handling Best Practices for HTTP Live Streaming - 514
  6. HLS Authoring Update - 515
  7. High Efficiency Image File Format - 513
  8. Image Editing with Depth - 508
  9. Introducing AirPlay 2 - 509
  10. Introducing HEIF and HEVC - 503
  11. Introducing MusicKit - 502
  12. Vision Framework: Building on Core ML - 506
  13. What's New in Audio - 501
  14. What's New in Photos APIs - 505
  15. Working with HEIF and HEVC - 511
System Framework
  1. Accelerate and Sparse Solvers - 711
  2. Advances in Networking, Part 1 - 707
  3. Advances in Networking, Part 2 - 709
  4. Best Practices and What’s New in User Notifications - 708
  5. Core ML in depth - 710
  6. Creating Immersive Apps with Core Motion - 704
  7. Developing Wireless CarPlay Systems - 717
  8. Enabling Your App for CarPlay - 719
  9. Introducing Core ML - 703
  10. Introducing Core NFC - 718
  11. Modernizing Grand Central Dispatch Usage -706
  12. Privacy and Your Apps - 702
  13. What's New in Apple Pay & Wallet - 714
  14. What's New in Core Bluetooth - 712
  15. What's New in HomeKit - 705
  16. What's New in Location Technologies - 713
  17. What's new in Apple File System - 715
  18. Your Apps and Evolving Network Security Standards - 701
  19. iOS Configuration and APIs for Kiosk and Assessment Apps - 716

References


Read More...

Friday, August 04, 2017

Self-reference and clousure

Here is a great short video explaining reference type and how to properly use it in closure by Brain's How to Build That App in YouTube.



Read More...

Wednesday, June 28, 2017

TestFlight for iOS Developers and Testers

TestFlight is an app provided by Apple. Here is the description by Apple about it:

TestFlight makes it easy to invite users to test your apps and collect valuable feedback before you release them on the App Store. You can invite up to 2,000 testers using just their email address.




Recently I have been using TestFlight app to deliver my app to testers. I found that this is a great platform between iOS app developers and app testers.

Add Testers by email

To make an app available for iOS users/testers to install and to test the app on their iOS devices, what an app developer needs to do is to request email from testers.

Then the developer adds the email to developer's test list from Apple iTunes Connect account. Tester will receive an email about test request.

From my experience, testers should first install TestFlight app from App Store on their iOS devices. This will make it easier to click or tap on the request email and see the app in TestFlight right away. Otherwise, testers will have to enter redeem code from the request test email.



Using TestFlight

Even though testers could open app directly on their iOS devices after initial installation, I would recommend to launch or open app each time from TestFlight. One of advantages is that testers will get the latest version from there. From TestFlight testers would notice new upgrades if the version of app is old.




From TestFlight, testers are able to see and install all previous versions, as well as description provided by developers. Tap on an app will provide more information about the app, information, Previous Builds, and more. This provides a convenient way to compare, verify and test issues found in the app.




If app is installed through TestFlight on one iOS device, the tester can also install the same app on other iOS devices (iPhone or iPad) by using the same AppleID, and then continue to his/her test on various iOS devices.

Send Feedback to Developers

TestFlight provides “Send Feedbacks” as a way to communicate with developer. The feedback is sent out by email. Therefore you can attach additional information such as screenshots, notes, and any related information. To add attachment in email, tap and hold on email body. Then a popup menu will show options to add photos.




I would strongly recommend testers sending at least one feedback to developer, even none issues are found. This will let developer know at least what iOS devices testers are using.

Welcome More Testers

Anyone with iOS devices 9.3 or higher are welcome to test my app, TapToCount - When, Where & What. What you need to do is to pass me your email. I will add you in my tester list.

As mentioned before, please install TestFlight app from App Store first. Then open TestFlight with your Apple ID.

One thing I notice is that you need to have Wifi or Cellular connection when you use TestFlight. It will connect to Apple server to find out what apps are available for your TestFlight. This will cost very small data communication. To install or update app, Wifi connection is recommended if data is concern for you.

You will receive test request by email for the first time. Tap on the link in email on your iOS device. You will see my app in TestFlight ready for installation. As my recommendation, open my app from TestFlight easy time. This will guarantee you will test my App in the newest version.

Keep in mind, there is 90 days expiration to use/test app through TestFlight. During your test period, please send me at least one of you test results, comments and any bugs or crashes you found.

References


Read More...

Wednesday, May 10, 2017

Apple Developer

Today is an important date for me. I just applied my Apple Developer from Apple web site. Actually I have been Apple Developer for long time, but I have not paid my annual fee as former developer yet. Even so, I have been doing development since the start of iPhone released. Now my app is ready for Apple Store.

The application process is very simple. First, submit my request from the web site. I applied as an company. What I need to get D&B's DUNS number for my company. This can be obtained for free from D&B Canada. Normally it requires 30 days to process. Another requirement is an email. The email cannot be gmail, hotmail, yahoo, or the likes. The recommended is email with company's domain name. I found that iCloud email is acceptable.

After submitting my request, I receive an email about acceptance. The next step is to agree Apple Developer Program License Agreement.

The last step is to pay my annual fee $99US or $119CAD, plus tax 5.95.

Within one hour after my annual fee payment, I am not registered developer for all Apple platform apps. The first three things I have to do are prompt when I login to my developer's account:


  • Connect to my team members (none so far)
  • Get Certificates which will be used for my apps
  • and set up iTunes connect account to manage my apps,


References



Read More...

Monday, May 08, 2017

Workspace in Xcode

One of interesting things I learned from Developing Apps for iOS CS193P, by Stanford U, is using Workspace in Xcode. This was explained in detail in lecture 9, TableView, at about 46minute.



Follow the instruction, what I did in my app project is to convert my project to Workspace from menu File-Save as Workspace...

Then from Finder to locate another project file and drag it to the Workspace, as two parallel projects.

One of project is a iOS Target type. This target has to be added to another project as embedded binary in project. This can be done by dragging the target to project settings.

The advantage of Workspace is that I can modify both project if needed.

Read More...

Thursday, May 04, 2017

Xcode and Swift Tips and Tricks

During my development of my iOS app, I have encountered some hurdles. Even though some of them are small ones, I did spend a lots of time to find solution to overcome them. Here are some in my past short period.

Can't find customized class from Storyboard


Normally customized view controller classes are used to handle specific requirement for some views. In Storyboard, this customized class can be specified in Storyboard right property panel "Show the identity inspector" tab.

For whatever reason, I may pressed space bar by chance in the area of Module. This caused the Module's value as None! As a result, I got this run time error:

Could not cast value of type 'UIViewController' (0x113f1b798) to 'MyProject.MyViewController' (0x113985200).

I spent hours trying to figure out why. Eventually, I found out the simple solution: change the module to my project.

This is what I had in my Storyboard for this customized class setting:



Hide Tabbar and use toolbar


In a tabar driven app, sometimes, I may need to hide tabbar and show a toolbar as alternative. To hide tabar for next view controller, it can be done in prepare(for segue: sender:) event.

  1. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  2.  ...
  3.  let vc = segue.destination
  4.  // call vc's hidebottombar
  5.  vc.hidesBottomBarWhenPushed = true
  6.  ...
  7. }

For the case of normal view controller, bar button item can be directly added to the bottom of the view. For the case of tableview controller, in order to show bar button item on the bottom, a toolbar has to be used to encapsulate bar button items. This can be done in storyboard.

However, it seems that there is no API or method to let vc to show or hide toolbar. At first, I found a solution to show or hide toolbar by adjusting toolbar y position in viewWillAppear event. The problem is that if user changes device from portrait to landscape, the toolbar will be off screen, disappeared. As a result, I have to adjust toolbar y position in the event of viewRotated.

To adjust toolbar y position, I add the following API to view controller as extension. This makes it easier in call this API to show toolbar.

  1. extension UIViewController {
  2.  func setToolBarShow(show: Bool, delay: Double = 2) {
  3.    if let toolbar = self.navigationController?.toolbar {
  4.      let newOriginY = UIScreen.main.bounds.height - toolbar.bounds.size.height
  5.      if toolbar.frame.origin.y != newOriginY {
  6.        toolbar.frame.origin.y = newOriginY
  7.      }
  8.      if delay > 0 {
  9.        // Make sure origin is set correctly
  10.        DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
  11.          if toolbar.frame.origin.y != newOriginY {
  12.            toolbar.frame.origin.y = newOriginY
  13.          }
  14.        }
  15.      }
  16.    }
  17.  }
  18. ...
  19. }

Here the trick to show toolbar in the events of viewDidAppeared and viewRotated is to delay adjusting toolbar y position. It seems that in both events, without delay, toolbar would not show. It may be something inside UIKit would not seeing this adjustment. With delay, the toolbar would show correctly at the bottom of the view.

Change navigation back button's title


In the case of parent VC to child VC by using navigation controller, the top-left button is used to pop off child VC and back to parent VC. The title of this button is by default the title of the parent VC. If the parent title is too long, it may make top text too crowded if the title of child VC is too long. One simple way to change top-left button title to "Back". This can be done by clearing parent title before pushing to child VC. UIKit will automatically use "Back" as the title.

Here is the solution to do that: clear view's title when pushing a new view controller. This can be done in the event of prepare() for segue.

One thing to remember is that to set view's title on the event of viewDidAppear(), otherwise, the view's title would be blank if the view is pushed back.

Resources


Read More...

Friday, April 28, 2017

Custom Store URL for CoreData

Recently I watched Developing iOS Apps with Swift by Stanford U, which was released in iTunes U on Jan 24, 2017. Even this course is for beginners, I still found many new concepts about iOS 10. One of the most interesting thing is about CoreData.

I tried to incorporate the new strategy strongly recommend by Paul Hegarty (instructor) in my App. Soon I realized that many new classes or methods by this strategy are only for devices in iOS 10.*. My app is for pre iOS 10 as well. After some consideration, I decided to use this strategy anyway. For pre iOS 10 cases, I'll continue to use UIManagedDocument to load CoreData database.

My app uses a customized store URL for loading data from CoreData database. The database is located in app's Documents folder. I added the new strategy into my project and tried to use the same URL to load database. To my surprise, my previous database are gone when I run the project in Simulator.

After deep investigation into where the SQLite database is, I found that the URL used by UIManagedDocument is actually pointing to the SQLite database two levels of directories down.



In above example, the URL by UIManagedDocument is defaultDatabase, but the SQLite database is persistentStore, under the directory of defaultDatabase/storeContent. However, the URL used by the new strategy, i.e., NSPersistentContainer, is the URL directly pointing to the SQLite database, persistentStore.

Actually, the first time I tried to load my database by previous URL caused my project crashing. As I discovered above, the URL pointing to defaultDatabase, which is a folder name.

This presents an issue for my app. Some users's device may be pre iOS 10. If they update their device to iOS 10.*, my app has to be able to adjust the previous URL to the correct database, so that users would not lose their data.

After some changes, my app can deal with this transition smoothly without losing their data.

This is a very good experience, incorporating new and efficient strategies into my app and dealing with prior iOS 10 devices.

References


Read More...

Saturday, March 04, 2017

Localization Experience in Swift Project

When I tried to jump into localization for my app, I thought it would be a simple job. Actually, I have encountered several hurdles during this progress. Here I would like to make some notes about issues I had experienced.

Bomb! Unexpected Exception


I started to add supporting to two sets of Chinese(my native language): mainly string files such as .strings, and .stringsdict files. This can be done by clicking on Localization button on the right Utilities panel in Xcode. By enabling localization, Xcode would move the English string or plist file from project root into en.lproj folder, and creating other language folders for localized resources, for example, zh-Hant.lproj for Simplified Chinese.

One thing I noticed is that plist file also has Localization section in Xcode right Utilities panel. I thought this could be localized and I did see some settings in some plist file requiring localization. Then I tried to localize plist file together. That's a mistake. See the following sections.


I have a long list of resource files. I spent about 2 days to finish localization for my project. With all the resource files ready, I stared to compile my project and tried to start my test on Simulator. Bomb! I saw this exception right away.




That's really bizarre exception. What does it mean by "Invalid argument"? It does not provide any detail clue about the exception. I had to try internet search to find out if any other people experienced the same issue.

No Solutions Anywhere


Soon I found out this is a common issue for some Swift developers and some suggestions were provided. Unfortunately, I tried all the solutions provided, but I could not resolve this exception in my case. Two days passed, I was really in struggle stage and with no clue to fix the issue.

With no way to get out, I stood back for a moment. With so many changes in my codes, I might mess up somewhere in my project. Instead of finding a way out of the maze, what I could do is to move my project back to the previous working version and redo the localization again. This was the last and difficult choice because I did not want to give up my localization effort.

Roll Back to Previous Working Version


I decided to discard all the changes in my codes from Source Control (fortunately, I have kept doing source code repository by using Xcode Source Control feature) and rolled back to previous version. This time, I started to do one change, and then compiling my project and running my app on Simulator at a time. In this way, I could figure out where the exception would be. I was also very careful coding localization to avoid any error causing unnecessary changes in my project.

I started from my app's settings, i.e, my app name, location privacy description, and app settings, where some localizations are required. I was so lucky that I soon located the issue which caused the exception.

Don't Localize info.plist


[app_name]-info.plist is a project property file, where project settings specific to my app are defined. For simplification, I call this info property file as info.plist in this blog. I need to localize my app display name and location privacy description in this plist.

In Xcode, all string files and plist files can be localized by clicking on Localize... button in Localization section on right Utilities penal.



When a resource file is localized, the English version file is moved from project root to en.lproj folder, and other localized files are created under corresponding language folders, for example, zh-Hans.lproj is the folder for Simplified Chinese resource files.

The problem is that info.plist file would be missing from project root if it were localized. The compile and installation processes require info.plist at project root. Actually, there is a resource file infoPlist.strings for info.plist localization purpose!

To verify this, I discard my changes again. For my working version, I found Identify section in my project settings (select my app as target, in General tab):



However, the same setting would be like as follows if the info.plist is localized.



Even I tried to locate the info.plist file from Choose button, I could not locate it from the dialog window.



Don't Localize Plist?


While I am writing this blog, I realize that none of plist files in my project require localization directly. Further exploration of the APIs Apple provides for localization, all strings files are automatically localized without any reference to device local settings from API interface calls. However, to load a plist, it seems that you have to specify a path for the plist file.

I remember that when I initially added a localization language to my project, from Info tab in project settings:




I saw a prompt dialog for adding new language for only two items: infoPlist.strings, which is for info.plist, and MainStoryboard.storyboard.



For info.plist file, Xcode provides corresponding infoPlist.strings file for localization. In my project, another place where a plist file is used is for my app default settings.

Localization of App Default Settings


The app default settings are defined in a bundle file: Settings.bundle, where a plist file Root.plist, which for default settings, and an English localization strings file within en.lproj folder, are created by Xcode at the time when the project was initially created.




To localize default settings for another language, a language folder and strings file have to be created manually(as in above zh-Hans.lproj and zh-Hant.lproj). The reason is that the plist file and strings files are within the bundle file and there is no Localization section in the right Utilities panel for adding new languages.

I found out that in order for settings working for any other languages, do not remove one item in Root.plist file: Strings Filename and its value as Root.



I had trouble to make default settings working while I was making changes in Root.plist file. I did not understand the usage of that item and removed it from the plist when I tried to clean up default settings. I was tumbled by this mistake. Anyway, it is a good experience and I now fully understand its importance.

References


Read More...

Friday, February 24, 2017

Enable Localization for Swift Project

My app is closing to finish stage. One feature I would like to have is to enable localization. Spending about hours exploration, I found the way to enable localization for my Swift project in Xcode 8.2.1.

The localization has to be set at project level. Open project settings first. Enable level panel and make sure to select project, you will find Localization section in Info section.

Then press + to add languages you like to support.




After this feature enabled, you may get prompt to enable localization for string, default plist and other localizable items. You can also click on Localizations in high panel for some resource files to add localization.

Read More...