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


Read More...

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.

  1. override func viewWillAppear(_ animated: Bool) {
  2.  // Call base class method will cause edit note jumpping
  3.  // super.viewWillAppear(animated)
  4.  ...
  5. }

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.

Read More...

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:

Command CompileSwiftSources failed with a nonzero exit code

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


Read More...

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


Read More...