I have been working on iOS projects with Xcode 11.1 for quite long time. Previously, I tried to update to 11.2. However, I experienced crashing issues after I compiled my project with Xcode. The problem was text editor. Each time when I tried to enter edit mode with text field UI, the app suddenly crashed. That was really bad experience.
Wednesday, January 08, 2020
Update to Xcode 11.3
Posted by D Chu at 8:41 AM 0 comments
Labels: iOS Development, Xcode
Friday, May 31, 2019
Add Remote Repository to Xcode Project
I have been using BitBucket web based repository for a while. I like its user interface, easy and convenient to view changes of my Xcode projects. Another nice thing about this service is that BitBucket allows to create private repositories and it is free.
To add a project to git repository, exit Xcode and open a Terminal.
Local Git Repository
For creating a local git repository, please read my previous blog. This step is important because the remote git repository is based on local git repository.
Remote Git Repository
Create a new repository on BitBucket first, for example, myTestPository. Use the following command in Terminal to link local repository to remote.
# Sets to new remote
git remote add origin remote git@bitbucket.org:yourAccountName/randomdraw.git
# Verifies the new remote URL
git remote -v
# Pushes the changes in your local repository up to the remote repository you specified as the origin
$ git push -u origin master
With the above steps completion, your remote git repository is ready for committing any new changes/updates.
References
- My previous blog on May 2, 2012: Configure git as XCODE Repository
- Remote Repository Service: BitBucket
- GitHub Help: Adding an existing project to GitHub using the command line
Posted by D Chu at 7:31 PM 0 comments
Labels: iOS Development, Xcode
Sunday, April 21, 2019
Bouncing Issue: Tap on Static TableView Content
Recently I found a really wired problem in my app. It took me several weeks to resolve the issue. I would like to write this blog to record this issue.
Here is the simplified case. I have a view controller based on UITableViewController. The table view is a static table view with several cells predefined in storyboard. Each cell has various height. The following is an example:
In cell Row2, there is a text view controller for editing a note.
When I run my app, I tap on edit button to change the text view into edit mode. This would cause the table view bouncing/jumping back and forth. At the end of this movement, the screen will stay at cell row 2 to allow me to edit the node. I don't like this kind of jumping movement.
When I test my app, I realize that I have another similar table view for editing note. That one does not have this jumping issue. Ok, I thought there must be something different to cause the issue.
I tried to compare every thing between those two screens, in storyboard settings and in view controller codes. I could not find anything obvious thing to cause the issue.
Finally, by carefully analyzing codes in both view controllers, I found that there is one line of code that caused the issue!
In smooth-none-jumper view controller, in the override func of viewDidAppear(), there is no call to its super class; while in the jumping one, the super class method of viewDIdAppear() is called, as in normal practice.
- override func viewWillAppear(_ animated: Bool) {
- // Call base class method will cause edit note jumpping
- // super.viewWillAppear(animated)
- ...
- }
This is the first time I encounter the case that the base class method should not be called, as in my comment above.
With this solution and change, my screen becomes smooth when I tap on the edit button:
By the way, I like to use static table view for my editing screens because the table view is a scrollable view.
Posted by D Chu at 5:57 PM 0 comments
Labels: iOS Development
Friday, March 29, 2019
Xcode 10.2, Swift 5, iOS 12.2 Released
On March 25, 2019, Apple formally released Xcode 10.2 with Swift 5, iOS 12.2, and others. With the release available, it is time for me to update my app projects. The following are some issues I have encountered and I think it is worthwhile to take some notes.
Warnings and Errors
The update, as same as my previous experiences, presented some issues I have to deal with. The migration process does not resolve all the issues. I got about 69 errors and 50 warnings. Those are the issues I have to check and change one by one. Fortunately, most of them are just API's changes, and Xcode does provides enough hints to tell what have changed. For example method name changes, and constants changes.
Fatal Error with no Clue
After I manually migrated all those changes. I got no warnings, and no errors in my codes. However, I had this no-clue fatal error:
As my project is so complex and has massive codes. I was lost at first. Where should I start to resolve the issue? Since the Xcode 10.2 and Swift 5 are quite new. I could not find direct or clear solution from web.
Even so, some people had similar issue in their project. I looked at their cases and solutions carefully. I have to say some of their analysis provide me lights out of dark. Finally, I got this issue resolved.
In the project settings, this was my previous setting in Build Settings -> Compilation Mode:
the setting is
Incremental. I found one solution is to change this to Whole Module as in the following:
Then I continued to build my project. This time, I got serval errors, which could not be found in
Incremental compilation mode. One error complains that override cannot be applied to method in extension.Here I give a simplified example: a base class implementing a none-objc delegate in iOS SDK's framework. When I wrote this base class, I put all the delegate methods within an extension of the base class. I like to use the strategy to separate delegate implementation in the extension block. This is OK in Swift 4 and 5 versions.
There are some occasions, I need to override some of those methods in inheritance classes. In the inheritance class I continue to put those override methods in extension block. In the previous version of Swift, ie ver 4, it is OK. However, this is not allowed in Swift 5. In other words, the override none-objc methods cannot be defined in extension.
It seems that Xcode Incremental compilation could not be identified the issue. Each file can be built or compiled without any errors. However, in the later or integration stage of compilation, Xcode could not resolve integration of the base class and inheritance class, based on Swift 5 rules. This may be Xcode bug. Fortunately, Xcode could start reporting and explaining errors in Whole Module mode.
I moved codes from extension to its class body block, those errors are gone!
After the successful build, I changed the compilation mode back iOS recommended default
Incremental mode again.References
- Wikipedia: Xcode
- Swift org: Swift 5 Released!
- SO question: Command CompileSwift failed with a nonzero exit code in Xcode 10
Posted by D Chu at 11:15 AM 0 comments
Labels: iOS Development, Xcode
Wednesday, March 06, 2019
Source Code Control and Task Management
I have been using Bitbucket on-line service as my iOS source code control for about one year. I really like this tool. As remove and online repository, it works very well, and I can use Xcode to check in & out my changes.
Another related tool is task management. I use Trello to log my tasks. Within Trello, I can manage several lists, such as todo, doing, and versions. Within each list, task can be added with comments. By using this great tool, I can add check change as a task, and move them over lists. In this way, I have overview of all my changes.
The good news is that all above on-line services are free, great for starter developers.
References
Posted by D Chu at 9:22 AM 0 comments
Labels: iOS Development, Web Tools
Tuesday, December 04, 2018
Add New Version to Core Data
There are sometimes when I need to update Core Data from existing version to a new version. In other words, I need to update Core Data database with changes on some entities. Apple provides very good framework to do that: Lightweight Migration. Here are my notes on how to add a new version to Core Data.
I am using my TapToCount-3W project as example.
In Xcode, select the data model in Project navigator:
From menu Editor, you will find Add Model Version....

Accept the default settings or make changes if you need. Make sure the base version is the most active version as base. In this case, I accept TapToCount 1.3 as my new version.
Change the property settings: identifier to 1.3 and current version to 1.3. A new version of database model is created and ready for update.
As it is indicated in Project navigator:
References
- Apple Developer Document: Lightweight Migration
- Apple Developer Document: Core Data Model Versioning and Data Migration
Posted by D Chu at 11:25 AM 0 comments
Labels: iOS Development, Xcode
Sunday, October 07, 2018
Run app on iOS 12.0 device from Xcode 9.4
Recently I updated my iPhone 5s with iOS 12.0. To my surprise, Xcode 9.4 on my Mac High Sierra dose not support iOS 12.0 device. That's hold on my app development.
My first reaction was to install the newest Xcode 10 beta 2 from Apple. The whole package is pretty big, 5GB+. That's OK. I downloaded the package and installed it. After that I was rushing to run my project in Xcode 10 (I did make a copy of the project to an external HD to run, to avoid any mass up). There were not much updates I had to make change in my app codes, however, I got a compiling error.
That was really painful time. The error seems to be related to linkage to iOS frameworks, no thing to do with my codes. I could not figure out what's wrong in Mac library system. Even worse, I could not run Xcode 9.4 with my project neither, with the similar linkage error.
I tried to look into my Mac library and Xcode framework dependencies. Remove and re-add frameworks. Nothing was working. I decided to stop further trying or mass-up. Took a break.
Fortunately, before I installed Xcode 10 beta 2, I checked in all my codes into my code-repository. I had my Mac Time Machine on. I know what is the time when I had the correct and latest working version of my Xcode 9.4, and it was just one day before. By using TM restoration, I finally got my app, in about 3 hours restoration of my Mac, working in Xcode 9.4.
With the successful restoration, I followed an advice from SO, copying iOS 12.0 supported folders from Xcode 10 beta to my Xcode 9.4.
Xcode-beta/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupportTo
/Applications/Xcode/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupportNow I can run my codes from Xcode 9.4 to my iPhone 5s device.
What's adventure and life-saving experience!
References
- SO discussion: iOS 12 not supported by Xcode 9.4
Posted by D Chu at 1:54 PM 0 comments
Labels: iOS Development, Xcode
Wednesday, October 03, 2018
Python script: MapIt.py
In addition to those changes, there are some steps that should done in Mac to make the script as executable in
terminal. I further make it working in Spotlight as well. Here are my notes.Script
Based on the video, I made minor changes on the script. Here is what I have now:- #! /usr/bin/env python3
- import webbrowser, sys, pyperclip
- sys.argv # example ['mapit.py', '870', 'Valencia', 'St.']
- address = 'Home'
- if len(sys.argv) > 1 :
- address = ' '.join(sys.argv[1:]) # ['870', 'Valencia', 'St.']
- else :
- address = pyperclip.paste()
- # https://www.google.com/maps/place/<address>
- webbrowser.open('https://www.google.com/maps/place/' + address)
The first line is important if you want to run the script directly from
terminal or Spotlight. Still there are some other steps to be done in order to run the script directly from terminal or Spotlight.Notice that I specify the name of python is
python3! Another minor change is the default address value: Home. I am using Mac and the Google map knows where my home is in my local Mac account.I saved the script at my local user account path:
~/Programming/py/mapit.py With script ready, I test the script in terminal:As soon as I type in the above command, a new tab page of Google Map is opened in Safari with the correct address.
Make the Script Executable
So far so good. However, I would prefer to open the script directly fromterminal, or from Spotlight, without specifying python3. For the case of terminal, first I have to make the script executable with the following commands:The second step is to add my script path to env
PATH so that I can simply type in mapit.py anywhere in command line. This is done by adding the path in ~/.bash_profile:- PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}:/Users/dchu/Programming/py"
- export PATH
With above setup ready, now I can run the script anywhere in
terminal:Isn't that cool?
Make the Script Runnable in Spotlight
Spotlight on Mac is a very convenient way to launch an app, to open a file, and to find information. However, unlike Windows Run, it not the way to direcly launch an app with arguments. Even though I set my script mapit.py as executable, I cannot run it from Spotlight. It will only open the script in Xcode!One way to get it work in
Spotlight is to change the script to .command extension. Mac OS will recognize this type of file as a runnable command.I prefer to keep my script as
.py. In UNIX or Mac, I can create an alias file of script: hard link(only hard link works in Spotlight). Here is the command to set it up:- ...$ cd ~/Programming/py
- ...$ ln mapit.py mapit.command
The good thing is that any change to my script will be automatically reflected in the command file.
In order to open the Google Map with specified address, I need to copy the address to clipboard first. Then I open my
Spotlight and type in mapit.command. It will pick up the address and open Google map in my default browser.The only thing is that I cannot specify address directly as arguments in
Spotlight. This is the limitation of it, and I cannot find a way to do that.This is why I need to use
pyperclip package in my script.
Note: another minor thing has to be done to make it runnable cleanly. The command is running in terminal. When the
Spotlight launches the command and opens the map in browser, it will leave the terminal in open status. I prefer to close the terminal automatically.To do that, go to terminal Preferences..., change the shell setting to Close the Windows:
The last word I have to say is that even the python script is very powerful and convenient to open a map with an address. I think Mac's Automator is much more powerful. It is easy to create (as a service), and can be set to selected text to open a map. Even though, I think it is a very good practice and great programming experience.
References
- My previous blog: Python and Packages
- Blog: Mac OX X Shortcuts, Aliases, Symbolic Lines, Hard Links
Posted by D Chu at 6:00 PM 0 comments
Tuesday, September 25, 2018
Python and Packages
Recently I started to watch a long training video on YouTube, 9+ hours. I just spent fraction of a few minutes daily as alternative refreshment. During the training period, I tired to use Idle app to practice some codes. Up to the point of installing third party packages, I could not get import to work on my Mac. I spent couple of days struggling and finally I figured it out. I think it is worthwhile to take some notes about this experience.
Tool to Install Packages
The first hurdle is that there is no
pip, a tool to install third party python packages, available in terminal on Mac. It seems that python is part of Mac OS system, but the version of python is an old version: 2.5 & 2.7. pip was not installed on my Mac.Eventually I got
pip installed by using easy_install tool:After that, I could install
pyperclip, a package for using clipboard copy and paste features.However, the import of
pyperclip in python shell and script still does not working!Version Issue
I could not find out any solution from web easily. It seems that all the solutions in the top search list I found from web are old ones, ie for python 2.*. From one place I read a hint about the issue: different versions of python on Mac. It is true that python came with Mac OS is version 2.3, 2.5 & 2.7. The newest version, for the time being, I installed on Mac is python 3.7.Further investigation, I found that the tool of
pip is actually used to install packages for python 2.7. The pip is located at the path of:The tool I need to install
pyperclip is actually pip3! This one is at the path of:When I sorted it out, it is so easy to install third party packages for python 3.7. For example:
For my interest, I further found out the locations of packages for different versions. For python 2.7, the location of package is at:
- find /Library/Python/ -name pyperclip
- /Library/Python//2.7/site-packages/pyperclip
and for python version 3.7 it is at:
- find /Library/Frameworks/Python.framework/ -name pyperclip
- /Library/Frameworks/Python.framework//Versions/3.7/lib/python3.7/site-packages/pyperclip
Python also in Different Versions!
One more interesting thing I found out is that, on my Mac, the name of python executable also has different ones! For the python came with Mac OS is actually version 2.5, and the executable name is python:
and for the newest version, 3.7 I installed, the name is python3:
From the terminal, the command of python will bring up to version 2.5:
- ...$ python
- Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
- [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
- Type "help", "copyright", "credits" or "license" for more information
- >>>
or type option
-h to get all available options. -V is for getting python version:- python -h
- ...
- Python 2.5
In order to run python3 from terminal, the
PATH has to be changed: adding python3's path. This is the result of my updated PATH:- echo $PATH
- /Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:
The
PATH is set in the file of .bash_profile:-
more ~/.bash_profile
- # Setting PATH for Python 3.7
- # The original version is saved in .bash_profile.pysave
- PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}:/Users/dchu/Programming/py"
- export PATH
Even with this change, you have to type the correct python executable name, ie python3, to enter python shell:
- python3
- Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24)
- [Clang 6.0 (clang-600.0.57)] on darwin
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import pyperclip
- >>>
Finally, I could do
import pyperclip in python shell and scripts without any errors.
By the way, here are the options to get all the commands, options, and the version for the tool of
pip or pip3:
- pip -h
- ...
- pip -V
- pip 18.0 from /Library/Python/2.7/site-packages/pip-18.0-py2.7.egg/pip (python 2.7)
- pip3 -V
- pip 10.0.1 from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)
References
- python.org
- Wikipedia: Python(programming language)
- w3school.com: python pip
- Open source: pyperclip (Notice: the installation script should be
pip3notpipfor python3!)
Posted by D Chu at 11:27 AM 0 comments
Labels: Python
Monday, September 17, 2018
Access to iOS Device Sandbox Data
If you have some files, database for example, in your iOS app, you may need to access to them. Recently, while I was working my app update, I was not sure if a major change would cause to lose my database. Before I run the app on my iPhone, I would like to keep a copy of my database to avoid any risk to lose my data over years.
There are couple ways to do that.
Backup to iTunes
This is very common way to keep a backup of a whole iOS device. First lunch iTunes on a Mac/Windows. Then connect your iPhone to the Mac/Windows. Click on iPhone icon to open a view, where backup is available.
This is very convenient to keep a backup before any adventure or after a period of time. In case of screwup, you can easily to restore your iPhone back to your previous status.
However, with this method, you could not see any files in your app sandbox, nor you could make any changes.
Devices in Xcode
The second way to make a backup of an app is available in Xcode. First, set your iPhone as target or active scheme. From the menu of
Windows->Devices and Simulators, open a view.
Here is the view:
Select the app you want to make a backup, then click the gear icon to bring up a menu list. In this way, the whole app sandbox is backed up to your local Mac. The content of the backup can be viewed through
Show Package Contents context menu.
This is pretty cool! Not only I can easily to restore the sandbox back to my iPhone, I could also view the content what I have in the app on my iPhone device. For example, the core data database, as you can see, is actually based on several files, all beginning with the same prefix name,
defaultDatabase, as I choose it as database name for my app.When I run my app in Xcode simulator, not only I could view, but also I could access to my app sandbox from Finder. There is no need to download or upload files to my app sandbox in Simulator.
I think that I could make some changes in the backup and restore back with changes I need. This is really handy for iOS developers in case needed.
Notice that you can only access to the app you are in development and installed to the device from Xcode, and the app has to be on your device. You can not see any other apps. If your app is installed through App Store, or Test Flight, you could not see it. This is for security reason. Anyway, it is good enough for me.
The Xcode I use is version 9.4 and iOS is version 11.4.
References
- SO discussion: There's a way to access the document folder in iphone/ipad (real device, no simulator)?
Posted by D Chu at 2:53 PM 0 comments
Labels: iOS Development, iPhone Applications
Thursday, August 23, 2018
ActionSheet as PopOver View
Recently, I have been working on my app update. In some cases, some actions could not be performed. I need to present a view to explain the reason. Alert view is a very common method to do that. Alert view is good to present the information, however, it is a modal view. User have to tap on OK or Cancel button to dismiss the alert view. I prefer the method of a popover view as alternative.
It is very easy to do that by using the same UIActionControler, and set the style as .actionSheet. This is well explained in Nick Meehan's post. Still there some thing missing is his post.
I would like to support both iPhon and iPad. For iPhone case, an action button should be added to dismiss the view. By default, the view is still a model view. You need a way to dismiss the alert view.
It is very interesting to find out that an action with .cancel style will change the modal view into a popover view. Further investigation, there is no need to add action handler to dismiss the view. The actionSheet will behaviour like a popover in iPhone.
Here are some codes.
- if let popoverController = alertController.popoverPresentationController {
- popoverController.sourceView = view
- popoverController.sourceRect =
- CGRect(x: view.bounds.midX, y: view.bounds.midY, width: 0, height: 0)
- popoverController.permittedArrowDirections = []
- } else {
- let cancelAction = UIAlertAction(title: UIHelper.dismissButtonTitle(), style: .cancel)
- alertController.addAction(cancelAction)
- }
Another interesting thing is that the cancel style action button will be displayed as an separate button on the bottom. You can specify any title to the button. I like it. This is the UI as in some Apple apps, such as deleting a message in message app.
Here is what I achieved in my update:
References
- Nick's blog: ActionSheet Popover on iPad in Swift
- My App: TapToCount-3W
Posted by D Chu at 1:32 PM 0 comments
Labels: iOS Development, iPhone Applications
Thursday, June 21, 2018
Debugging with Xcode and LLDB
Really cool stuff on lldb, Xcode debug power tool. As well there is one training video from WWDC 2018: Advanced Debugging with Xcode and lldb.
Posted by D Chu at 7:44 PM 0 comments
Labels: Debugging with Xcode and LLDB, iOS Development, Xcode
Tuesday, April 17, 2018
Pace Calculation in Swift
I need to add a new feature to show pace in my iOS App(TapToCount -3W). By given two dates and two locations as input, the pace can be easily calculated in the formula:
pace = duration / distance
Duration
In swift the duration can be obtained in following codes:
// dt1 and dt2 are Date types
let timeInterval = dt2.timeIntervalSince(dt1)
The func
timeIntervalSince call will return seconds as time interval between two days.
Distance
The distance between two locations is obtained
// loc1 and loc2 are CLLocation type
let dist = dist2.distance(from: dist1)
where dist is the distance value in meters.
Support Localization and Accessibility
It seems that the pace calculation is so simple to get. Hold on. iOS provides APIs to support metric or imperial measurement system. It would be nice to get pace calculation result either in metric or imperial system. This can be easily detected by the following codes.
let locale = NSLocale.current
let metricSystem = locale.usesMetricSystem
In my iOS app, I presented the pace calculation result in human readable format. For example, 6'34" would be "6 min, 28 secs".
Further more, the pace result may be in hours, or even years, depending on inputs of dates and locations. My pace calculation is more generic to support a wide range of cases. To obtain readable result, it can be done by using Swift codes:
1 let fm = DateComponentsFormatter()
2 fm.allowedUnits = [.year, .day, .hour, .minute, .second]
3 fm.unitsStyle = .short
4 let short = fm.string(from: value)
5 fm.unitsStyle = .full
6 let full = fm.string(from: value)
The
allowedUnits property specifies what readable units should be used. Here is the complete units from seconds to years, and only first none zero value's unit will be presented, for example, 2 hrs, 15 min, 23 secs. This example is in a short form. There is no need to worry about languages. The API will do the localization automatically. Very nice!The short form is good for UI presentation. The full form will spell out whole units, such as "2 hours, 15 minutes, 23 seconds". This would be great for accessibility support, for example, label's accessibilityValue. The localization for full form is done automatically as well.
I tested this pace calculation in my iOS app. The following is the screenshot of my mountain hiking, Ha Ling Peak, last Sunday.
and this is my running result today when I was doing my test.
and here is one more test I did. I changed the iPhone language to Traditional Chinese.
You may notice that when the pace result is in years or long days, the last units minute and second are dropped out, since such small amount is so insignificant. The complete codes are available in my answer in StackOverflow discussion.
References
- StackOveflow QA: Running Pace Calculation in Swift
- My iOS app: TapToCount - 3W
Posted by D Chu at 7:13 PM 0 comments
Labels: iOS Development, Swift
Sunday, January 14, 2018
Autoresizing and Constraints to Safe Area
Recently one issue has troubled me for several days. Finally I just figured it out. I think it is worthwhile to make a note about my experience.
I have an app with several tab views, all displaying similar data in table view. I tried to add search feature for the app. The way to add search controller for iOS 11 and iOS 10 is different. For iOS 11, the search controller is added to navigation controller while the search controller is added to table view's header for iOS 10. My test of iOS 11 works great. However, the test for iOS 10 presented an issue.
In the first tab view, the search works well, but not in the second one. The issue is that the content of table view is shifted up about 40 pixels in the second tab.
Here is the search bar at initial status:
Tap on search bar to start search. Notice that the content of table view is shifted up 40, about half of the first row is behind the search bar.
Even worse, I could not see the search bar if I select a row to the next screen and back to the main screen. The search bar is moved up, not in reachable view.

The search function in the first tab view works without this issue. Therefore, the best way is to compare the difference between two tab view controllers. There are not any major difference. I tried to disable some codes in viewDidLoad, viewWillAppear, and viewDidAppear to make them behaviour the same. Still I could not resolve the issue.
Finally, I noticed there is a difference in storyboard. The table view of the first tab is using autoresizing.
while the second tab's view controller uses constraints for its table view!
I removed four constraints and set autoresizing for the table view of the second tab. With this change, the search feature works well as expected.
It seems that autoresizing for iOS 11 is almost as same as four constraints to its safe area (which is introduced in iOS 11 but not exist in iOS 10). Even it would fall back to previous layout guide, it seems not working in the same way for table view in this case. For old iOS back from 11, try to not use safe area as reference for table view constraints.
Test for all supported iOS versions is very important!
Posted by D Chu at 3:05 PM 0 comments
Labels: iOS Development
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
- WWDC 2017 video session 245: Building Apps with Dynamic Type
- WWDC 2017 video session 204: Updating Your App for iOS 11
Posted by D Chu at 3:01 PM 0 comments
Labels: iOS Development, WWDC
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
- Blog: Self-sizing Table View Cells
- My iOS App: TapToCount
Posted by D Chu at 3:13 PM 0 comments
Labels: iOS Development, Xcode
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.
Posted by D Chu at 3:27 PM 0 comments
Labels: iOS Development
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
Posted by D Chu at 5:35 PM 0 comments
Labels: iOS Development
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
- The App Store: TapToCount - 3W
- News and support web blog: TapToCount - 3W
Posted by D Chu at 9:33 PM 0 comments
Labels: iOS Development, iPhone Applications
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
Posted by D Chu at 4:08 PM 0 comments