Friday, March 18, 2022

Removing Duplicated Lines by VIM

Recently I have interest in GPS location coordinates. In my TapToCount-3W iOS app, there is a feature to record location information for each tap.

I have been puzzled by a scenarior for long time. For example, if I make several taps at same location, the GPS locations spead within a range, several tens of meters to meters apart, 30 meters or 8 meters as examples.

Further invetigation, I found that the decimal points of GPS coordinates are related to location accuracy. The more decical points are in coordindates, the more accuracy.

VIM is a powerful tool. The following is a real case of my invetigation and analysis of GPS coordindates by using VIM.

Export GPS Information

First, I have to get GPS location coordates from my app. I use the Export feature to share the result of cvs file to my mac.


Using Numbers to open the csv file. The tap information includes my sleep times between Dec 2018 to Mar 2022, 7484 lines of taps I made. From GPS coordinates, I see the decimal points up to 14 digits.

For example, here is a coordinate of latitue, longitue, and altitue value:
53.55404449631790,	-113.2990255394140,	692.3739891052250

Find Duplicate GPS Information

7484 lines are quite a lot of information. I need to find out if there is any duplicated information.

Use the following command to find duplicate coordinate information:
/\(T-\d\)\(.*\)\n\(.*\2\n)\+

Match pattern explaination: first group beginning with "T-" and a digit, then any charts (coordinates) as second group, new line, next or more lines of any charts followed by the matched second group (coordinates).

The result is as followings:


Remove Duplicate Coordinate Lines

With about search result, I can then proceed removing duplicate coordinate lines.

Use the following command to remove duplicate coordinate information:
:%s/\(T-\d\)\(.*\)\(\n.*\2\)\+/\1\2/

Replacement command explaination: replace the matched pattern (duplicate GPS coordinate lines with group 1 and group 2 defined in the matched pattern.

Analysis Results

With VIM search and replacement as a convenience and powerful tool, I can do my research and analysis on GPS coordinates collected in my TapToCount-3W app.

Using Numbers, I can get coordinate values with different decimal digits, and find out what duplicate coordinates.

7,485 Taps with GPS coordindates
Decimal
Places
Degrees
Duplicates
Unique
0
0
5246
2239
1
0.1
5245
2240
2
0.01
5245
2240
3
0.001
5222
2263
4
0.000 1
4711
2774
5
0.000 01
4638
2847
14
0.000 000 000
000 00
577
6908

Based on above analysis, I think that the best decimal points should 5, 4, or 3 places, with accuracy corespoinding to +/-0.555m, +/-5.55m, or +/-55.5m. This will reduce duplicate coordinates up to 68% to 70%.

By using VIM, I did further analysis. I export a group of taps from Jan 1, 2022 to now (Mar 19, 2022), which I know for certain that they(454 taps) were tapped at the same location. The following are 2 results: one with altitute into consideration and another with no altitute.

454 Taps with GPS coordindates and altitude
Decimal
Places
Degrees
Duplicates
Unique
0
0
444
10
1
0.1
444
10
2
0.01
444
10
3
0.001
442
12
4
0.000 1
255
199
5
0.000 01
434
20
14
0.000 000 000
000 00
444
10

454 Taps with GPS coordindates and NO altitude
Decimal
Places
Degrees
Duplicates
Unique
0
0
453
1
1
0.1
453
1
2
0.01
453
1
3
0.001
452
2
4
0.000 1
444
10
5
0.000 01
33
421
14
0.000 000 000
000 00
8
446

With above research results, they helps me better to understand GPS coordindate information, and to take better and effective strategies for updating my app freatures and interfaces for my app users.

References

Read More...

Friday, November 26, 2021

WWDC 2021 Videos

This year Apple continued its WWDC online. The second time of the conference videos are much better than the last year. Each one is about less than one hour right on the topic. I waited one month after its finish. In this way, the video list is stable and complete.

The following is the complete list I have watched.
  1. Add Intelligence to your widgets iOS, macOS Sep 11
  2. AR Quick Look, meet Object Capture iOS, macOS Sep 11
  3. ARC in Swift: Basics and beyond iOS, macOS, tvOS, watchOS Sep 11
  4. Accelerate machine learning with Metal Performance Shaders Graph iOS, macOS Sep 11
  5. Accelerate networking with HTTP/3 and QUIC iOS, macOS, tvOS, watchOS Sep 11
  6. Accessibility by design: An Apple Watch for everyone watchOS Sep 11
  7. Add rich graphics to your SwiftUI app iOS, macOS, tvOS, watchOS Sep 11
  8. Add support for Matter in your smart home app iOS Sep 11
  9. Adopt Quick Note iOS, macOS Sep 12
  10. Analyze HTTP traffic in Instruments iOS, macOS, tvOS, watchOS Sep 12
  11. Apple’s privacy pillars in focus iOS Sep 12
  12. Automate CloudKit tests with cktool and declarative schema iOS, macOS, tvOS, watchOS Sep 12
  13. Bring Core Data concurrency to Swift and SwiftUI iOS, macOS, tvOS, watchOS Sep 12
  14. Bring Recurring Leaderboards to your game iOS, macOS, tvOS Sep 13
  15. Bring accessibility to charts in our app iOS, macOS, tvOS, watchOS Sep 13
  16. Build Mail app extensions macOS Sep 13
  17. Build a research and care app, part 1: Setup onboarding iOS Sep 13
  18. Build a research and care app, part 2: Schedule tasks iOS Sep 13
  19. Build a research and care app, part 3: Visualize progress iOS Sep 13
  20. Build a workout app for Apple Watch watchOS Sep 13
  21. Build apps that share data through CloudKit and Core Data iOS, macOS tvOS, watchOS Sep 14
  22. Build custom experiences with Group Activities iOS, macOS, tvOS Sep 14
  23. Build dynamic iOS apps with the Create ML framework iOS Sep 14
  24. Build interactive tutorial using DocC iOS, macOS tvOS, watchOS Sep 14
  25. Build interfaces with style iOS, macOS Sep 14
  26. Build light and fast App Clips iOS Sep 14
  27. Capture and process ProRAW images iOS, macOS Sep 14
  28. Capture high-quality photos using view formats iOS, macOS Sep 15
  29. Classify hand poses and actions with Create ML iOS, macOS Sep 15
  30. Connect Bluetooth devices to Apple Watch watchOS Sep 15
  31. Coordinate media experiences with Group Activities iOS, macOS, tvOS Sep 15
  32. Coordinate media playback in Safari with Group Activities macOS Sep 15
  33. Craft search experiences in SwiftUI iOS, macOS, tvOS, watchOS Sep 15
  34. Create 3D models with Object Capture iOS, macOS Sep 15
  35. Create 3D workflows with USD iOS, macOS Sep 15
  36. Create accessible experiences for watchOS watchOS Sep 15
  37. Create audio drivers with DriverKit macOS Sep 16
  38. Create custom audio experiences with ShazamKit iOS, macOS, tvOS, watchOS Sep 16
  39. Create custom symbols iOS, macOS, tvOS, watchOS Sep 16
  40. Create image processing apps powered by Apple Silicon iOS, macOS Sep 16
  41. Cross reference content with the Apple Music API iOS macOS Sep 16
  42. Customize and resize sheets in UIKit macOS Sep 16
  43. Customize your advanced Code Cloud workflows iOS, macOS, tvOS, watchOS Sep 16
  44. Deliver a great playback experience on tvOS tvOS Sep 16
  45. Demystify SwiftUI iOS, macOS, tvOS, watchOS Sep 16
  46. Design for Group Activities iOS, macOS, tvOS Sep 16
  47. Design for Safari 15 iOS macOS Sep 16
  48. Design for spatial integration iOS watchOS Sep 17
  49. Design create actions for Shortcuts, Sir, and Suggestions iOS, macOS, watchOS Sep 17
  50. Detect and diagnose memory issues iOS, macOS Sep 17
  51. Detect bugs early with the static analyzer iOS, macOS, tvOS, watchOS Sep 17
  52. Detect people faces and poses using Vision iOS, macOS Sep 17
  53. Develop advanced web content iOS, macOS Sep 17
  54. Developer spotlight: Accessibility Sep 17
  55. Diagnose Power and Performance regressions in your app iOS, macOS Sep 17
  56. Diagnose unreliable code with test repetitions iOS, macOS, tyOS, watchOS Sep 17
  57. Direct and reflect focus in SwiftUI iOS, macOS, tvOS, watchOS Sep 17
  58. Discovery Metal debugging, profiling, and asset creation tools iOS, macOS, tvOS Sep 17
  59. Discover Web Inspector improvements iOS, macOS Sep 18
  60. Discover account-driven User Enrollment iOS, macOS Sep 18
  61. Discover and curate Swift Packages using Collections iOS, macOS, tvOS, watchOS Sep 18
  62. Discover breakpoint improvements iOS, macOS, tvOS, watchOS Sep 18
  63. Discover build-in sound classification in SoundAnalysis iOS, macOS, tvOS, watchOS Sep 18
  64. Discover compilation workflows in Metal iOS, macOS, tvOS Sep 18
  65. Discover concurrency in SwiftUI iOS, macOS, tvOS, watchOS Sep 18
  66. Discover geometry-aware audio with the Physical Audio Spatialization Engine (PHASE) iOS, macOS Sep 18
  67. Discover rolling clips with ReplayKit iOS, macOS, tvOS Sep 19
  68. Discoverable design iOS, macOS, tvOS, watchOS Sep 19
  69. Distribute apps in Xcode with cloud signing iOS, macOS, tvOS, watchOS Sep 19
  70. Dive into RealityKit2 iOS macOS Seep 19
  71. Donate intents and expand your app’s presence iOS, watchOS Sep 19
  72. Elevate your DocC documentation in Xcode iOS, macOS, tvOS, watchOS Sep 19
  73. Embrace Expected Failures in XCTest iOS, macOS, tvOS, watchOS Sep 19
  74. Enhance your app with Metal ray tracing iOS, macOS Sep 19
  75. Evaluate videos with the Advanced Video Quality Tool iOS, macOS, tvOS Sep 19
  76. Explore ARKit 5 iOS Sep 19
  77. Explore Core Image kernel improvements iOS, macOS Sep 19
  78. Explore Digital Crown , Trackpad, and iPad pointer automation iOS, macOS, tvOS, watchOS Sep 19
  79. Explore HDR rendering with EDR iOS, macOS Sep 19
  80. Explore HLS variants in AVFoundation iOS, macOS, tvOS, watchOS Sep 19
  81. Explore Nearby Interaction with third-party accessories iOS, macOS, tvOS, watchOS Sep 19
  82. Explore Safari Web Extension improvements iOS, macOS Sep 19
  83. Explore ShazamKit iOS, macOS, tvOS, watchOS Sep 19
  84. Explore UWB-based car keys iOS, macOS Sep 20
  85. Explore Verifiable Health Records iOS Sep 20
  86. Explore WKWebView additions iOS, macOS Sep 20
  87. Explore Xcode Cloud workflows iOS, macOS, tvOS, watchOS Sep 20
  88. Explore advanced project configuration in Xcode iOS, macOS, tvOS, watchOS Sep 20
  89. Explore advanced rendering with RealityKit 2 iOS, macOS Sep 20
  90. Explore bindless rendering in Metal iOS, macOS, tvOS Sep 20
  91. Explore dynamic pre-rolls and mid-rolls in HLS iOS, macOS, tvOS Sep 20
  92. Explore hybrid rendering with Metal ray tracing iOS, macOS Sep 20
  93. Explore low-latency video encoding with VideoToolbox iOS, macOS Sep 21
  94. Explore structured concurrency in Swift iOS, macOS, tvOS, watchOS Sep 21
  95. Explore the SF Symbols 3 app iOS, macOS, tvOS, watchOS Sep 21
  96. Explore the catalog with the Apple Music API iOS Sep 21
  97. Extract document data using Vision iOS, macOS Sep 21
  98. Faster and simpler notarization for Mac apps macOS Sep 21
  99. Focus on iPad keyboard navigation iOS Sep 21
  100. Get ready for iCloud Private Relay iOS, macOS, tvOS, watchOS Sep 21
  101. Get ready to optimize your App Store product page iOS Sep 21
  102. Host and automate your DocC documentation iOS, macOS, tvOS, watchOS Sep 21
  103. Immerse your app in spatial audio iOS, macOS, tvOS Sep 21
  104. Improve MDM assignment of Apps and Books iOS, macOS, tvOS Sep 22
  105. Improve access to Photos in your app iOS, macOS Sep 22
  106. Improve global streaming availability with HLS Content Steering iOS, macOS, tvOS Sep 22
  107. Keynote iOS, macOS, tvOS, watchOS
  108. Localize your SwiftUI app iOS, macOS, tvOS, watchOS Sep 22
  109. Make blazing fast lists and collection views macOS Sep 22
  110. Manage devices with Apple Configurator iOS, macOS Sep 22
  111. Manage in=-app purchases on your server iOS, macOS, tvOS Sep 23
  112. Manage software updates in your organization iOS, macOS Sep 23
  113. Measure health with motion iOS, macOS Sep 23
  114. Meditation for fidgety skeptics Sep 23
  115. Meet AsyncSequcence iOS, macOS, tvOS,watchOS Sep 23
  116. Meet ClassKit for file-based apps iOS Sep 23
  117. Meet DocC documentation in Xcode iOS, macOS, tvOS, watchOS Sep 23
  118. Meet Group Activities iOS, macOS, tvOS Sep 23
  119. Meet MusicKit for Swift iOS, macOS, tvOS watchOS Sep 23
  120. Meet Safari Web Extensions on iOS iOS, macOS Sep 23
  121. Meet Shortcuts for macOS iOS, macOS Sep 24
  122. Meet StoreKit 2 iOS, macOS, tvOS, watchOS Sep 25
  123. Meet TestFlight on Mac iOS, macOS, tvOS Sep 25
  124. Meet TextKit 2 iOS, macOS Sep 25
  125. Meet Xcode Cloud iOS, macOS, tvOS, watchOS Sep 25
  126. Meet async/await in Swift iOS, macOS, tvOS, watchOS Sep 26
  127. Meet declarative device management iOS, macOS Sep 26
  128. Meet in-app events on the App Store iOS, macOS, tvOS Sep 26
  129. Meet private-preserving ad attribution iOS, macOS Sep 26
  130. Meet the Location Button iOS, macOS, tvOS, watchOS Sep 26
  131. Meet the Screen Time API iOS Sep 26
  132. Meet the Swift Algorithms and Collections packages iOS, macOS, tvOS, watchOS Sep 27
  133. Meet the UIKit button system iOS, macOS, tvOS, watchOS Sep 27
  134. Mitigate fraud with App Attest and DeviceCheck iOS, macOS, tvOS Sep 27
  135. Move beyond passwords iOS, macOS Sep 27
  136. Optimize for 5G networks iOS Sep 27
  137. Optimize for variable refresh rate displays iOS, macOS Sep 27
  138. Optimize high-end games for Apple GPUs iOS, macOS, tvOS Sep 27
  139. Out of this world… on to Mars Sep 27
  140. Platforms State of the Union
  141. Practice audio haptic design iOS Sep 27
  142. Principles of great widgets iOS, macOS Sep 27
  143. Protect mutable state with Swift actors iOS, macOS, tvOS, watchOS Sep 27
  144. Qualities of a great Mac Catalyst app macOS Sep 29
  145. Qualities of great iPad and iPhone apps on Macs with M1 iOS, macOS Sep 30
  146. Reduce network delays for your app iOS, macOS, tvOS, watchOS Sep 30
  147. Review code and collaborate in Xcode iOS, macOS, tvOS, watchOS Sep 30
  148. SF Symbols in SwiftUI iOS, macOS, tvOS, watchOS Sep 30
  149. SF Symbols in UIKit and AppKit iOS, macOS, tvOS Sep 30
  150. Safeguard your accounts, promotions, and content iOS, macOS, tvOS, watchOS Sep 30
  151. Secure login with iCloud Keychain verification codes iOS, macOS Oct 1
  152. Send communication and Time Sensitive notifications iOS, macOS, watchOS Oct 2
  153. Showcase app data in Spotlight iOS, macOS Oct 2
  154. Simplify sign in for your tvOS apps tvOS Oct 2
  155. Streamline your localized strings iOS, macOS, tvOS, watchOS Oct 2
  156. Support Full Keyboard Access in our iOS app iOS Oct 2
  157. Support customers and handle refunds iOS, macOS, tvOS, watchOS Oct 2
  158. Swift concurrency: Behind the scenes iOS, macOS, tvOS, watchOS Oct 2
  159. Swift concurrency: Update a sample app iOS, macOS, tvOS, watchOS Oct 3
  160. Swift Accessibility: Beyond the basics iOS, macOS, tvOS, watchOS Oct 3
  161. SwiftUI on the Mac: Build the fundamentals macOS Oct 3
  162. SwiftUI on the Mac: The finishing touches macOS Oct 3
  163. Symbolication: Beyond the basics iOS, macOS, tvOS, watchOS Oct 3
  164. Sync files to the cloud with FileProvider on macOS macOS Oct 3
  165. Tailor the VoiceOver experience in your data-rich apps iOS, macOS Oct 4
  166. Take your iPad apps to the next level iOS Oct 4
  167. Tap into virtual and physical game controllers iOS, macOS, tvOS Oct 4
  168. The practice of inclusive design iOS, macOS, tvOS, watchOS Oct 4
  169. The process of inclusive design iOS, macOS, tvOS, watchOS Oct 4
  170. There and back again: Data transfer on Apple Watch watchOS Oct 4
  171. Transition media gaplessly with HLS iOS, macOS, tvOS Oct 4
  172. Triage TestFlight crashes in Xcode Organizer iOS, macOS, tvOS, watchOS Oct 4
  173. Tune your Core ML models iOS, macOS, tvOS, watchOS Oct 5
  174. Ultimate application performance survival guide iOS, macOS Oct 5
  175. Understand and eliminate hangs from your app iOS, macOS Oct 5
  176. Use Accelerate to improve performance and incorporate encrypted archives iOS, macOS, tvOS, watchOS Oct 5
  177. Use async/await with URLSession iOS, macOS, tvOS, watchOS Oct 5
  178. Use the camera for keyboard input in your app iOS Oct 5
  179. WWDC21 Apple Design Awards iOS, macOS, tvOS, watchOS Oct 5
  180. What’s n ew in AVKit iOS, macOS Oct 5
  181. What’s new in App Analytics iOS, macOS, tvOS, watchOS Oct 5
  182. What’s new in App Clips iOS Oct 5
  183. What’s new in AppKit macOS Oct 5
  184. What’s new in CloudKit iOS, macOS, tvOS, watchOS Oct 5
  185. What’s new in Foundation iOS, macOS, tvOS, watchOS Oct 6
  186. What’s new in Mac Catalyst macOS Oct 6
  187. What’s new in SwiftUI iOS, macOS, tvOS, watchOS Oct 6
  188. What’s new in UIKit iOS Oct 6
  189. What’s new in Wallet and Apple Pay iOS, macOS, tvOS, watchOS Oct 6
  190. What’s new in watchOS 8 watchOS Oct 6
  191. What’s new in Swift iOS, macOS, tvOS, watchOS Oct 6
  192. What’s new in AVFoundation iOS, macOS, tvOS, watchOS Oct 6
  193. What’s new in Game Center: Widgets, friends, and multiplayer improvements iOS, macOS, tvOS Oct 6
  194. What’s new in SF Symbols iOS, macOS, tvOS, watchOS Oct 6
  195. What’s n ewe in camera capture iOS, macOS Oct 7
  196. What’s new in managing Apple devices iOS, macOS Oct 7
  197. Write a DSL in Swift using result builders iOS, macOS, tvOS, watchOS Oct 7
  198. Your guide to keyboard layout iOS Oct 7

References

  • WWDC 21

Read More...

Friday, September 25, 2020

Xcode 12.0 and ToolChain Error

I updated my Xcode two days ago. After the update, I got a warning error about ToolChain failure: 

/Library/Developer/Toolchains/swift-2.2-SNAPSHOT-2015-12-10-a.xctoolchain:1:1: failed to load toolchain: 'Version' parse error: Could not parse version component from: 'swift-2'

There is no further explanation about this error in Xcode. After Google search, I found one solution. It seems that it is caused by Xcode missing remove it when I did Xcode update.


As in the suggestion, the tool chain has to be removed from /Library/Developer/ToolChain/. In my case, there are two items in the direct:

$ ls
swift-2.2-SNAPSHOT-2015-12-10-a.xctoolchain
swift-latest.xctoolchain

The first one is a directry, and the second is a link to the directory. For safe case, I use Finder to the directory, and compress those two items first as Archive.zip. Then Remove them completely.

I have to quit Xcode and relaunch Xcode again to do clean build. This time warning error is gone.

My Update Xcode 12.0


The update process was painful. It toke long time to download. I got failure 2 twice.

I had Xcode update frustrating experience before. There was one time the updated Xcode version could not build my project. I had to rollback to old version from TimeMachine backup.

From that experience, I have been kept copy of previous Xcode to external disk first. Then I remove Xcode from Applications. In this way, this time I did clean installation of Xcode 12.0. Another reason is that I do not have enough space in my hard disk to do update. I had to remove old version to get more space.

This clean installation may missed the step to remove ToolChain.

Read More...

Tuesday, June 23, 2020

One-on-One Support from Apple

WWDC2020 was launched this week. In the past, WWDC conferences were all held in US. This year, because of COVID19 and social distance rules,WWDC is the first time on virtual web. The greatest news is that all Apple registered developers are all able to attend the WWDC without paying expensive registration, travel and hotel fees. This is first time Apple trying virtual WWDC.

On the first day, I watched the keynote speech yesterday. From my personal option, I think the virtual meeting is organized much more efficient and smooth, when transfering from one person to another. This can be done without any delay.

I watched Sean Allen's Swift News on YouTube. Among many topics about WWDC,he mentioned One-on-one Labs support, which was only available on site at WWDC. Now everything is on virtual. I quickly searched from Apple Developer's web page. It is true that one-on-one support is available on request. I made my request. I have been struggling on one UI issue for quite long time and still could not figure out any good solution. Within seconds, I got confirmation that my one-on-one support is scheduled tomorrow morning. That's awesome!

 


I have hight hope that I could get expert support directly from Apple to diagnose my issue and hope a solution would help to get the issue resolved.

Update on Jun 24 11MT: Just finished 1 on 1 labs support. I demonstrated my issue and showed what I have done in Xcode. The issue seems new to Apple support. He could not provide any solution and suggested me to submit a bug report on this issue.

The issue is that I have a screen with toolbar on bottom. There is one UIBarButton there. Most of time, the button shows normally. However, after a while, it would not visible when the screen brought up. I noticed that the issue is related to iPhone without physical Home button, ie, my Xr. The button still reacts to tap action even when it is invisible. It looks like that the button's tint color is as same as toolbar color, which causes button invisible.

References


Read More...

Monday, April 20, 2020

Use div for Table Layout in HTML

table HTML Tag has been in HTML for long time to show table-like layout. Now div is more powerful tag to display a block of text, and this can be used for table-like layout.

The basic concept is to use css styles as a way to instruct div to show block of text in table-like layout. After search on web, I found a couple ways to use div, and I place the correspoding ccs styles in Blogger's templates.

The following are some ccs classes in Blogger template:

/* -- no border table using div class */
.nbTable { 
  display: table;
  width: 100%;
} 
.nbTableRow {
  display: table-row;
}
.nbTableHeadRow {
  display: table-header-group; 
  font-weight: bold;
} 
.nbTableBody {
  display: table-row-group; 
} 
.nbTableFoot {
  display: table-footer-group; 
}
.nbTableCell, .nbTableHead {
  display: table-cell; 
}
.nbTableCell1Line, .nbTableHead1Line {
  display: table-cell;
  white-space: nowrap;
}

/* -- table with border using div class */
.bTable {
  display: table;
  width: 100%;
} 
.bTableRow {
  display: table-row;
}
.bTableCell, .rTableHead {
  display: table-cell;
  padding: 3px 10px;    
  border: 1px solid #999999;
}
.bTableCell1Line, .rTableHead1Line {
  display: table-cell;
  white-space: nowrap;
  padding: 3px 10px;
  border: 1px solid #999999;
}
.bTableHeadRow {
  display: table-header-group;
  background-color: #ddd;
  font-weight: bold;
}
.bTableFoot {
  display: table-footer-group;
  font-weight: bold;
  background-color: #ddd;
}
.bTableBody {
  display: table-row-group;
}

Read More...

Sunday, April 05, 2020

Use VIM to Clean Up HTML

I have set up a blog at Blogger with more than one authors so that we can write our stories, observations about COVID-19. Some authors do not have any knowledge about HTML or how to write clean blogs there. As a result, the blogs they created contains massy HTML tags, either cause them frustration to edit text or inconsistent styles spreading blog text.





I am tech support person working hard behind scenes. One of my jobs is to clean up their blogs to remove unnecessary HTML tags. Here is one example how complexed HTML is:




VIM as Effective Tool


It is really tedious and time consuming to manually remove HTML paired tags. For example:

<span ...>...</span>

I realize that VIM is a great tool for help!

Here is the command to find out span paired block in HTML:

/<span\(\_.\{-}\)\@=\_.\{-}>

search for start patten <span any chars afterwards including mutilple lines till >.

Here is the result:





That's very exiting! With this confirmation test, it will be just line of VIM replace command to clean up span tags:

%s:<span\(\_.\{-}\)\@=\_.\{-}>::g  





More VIM command for finding and replacing


/<\/span\(\_.\{-}\)\@<=\_.\{-}> ## find </span>
:%s:<\/span\(\_.\{-}\)\@=\_.\{-}>::g ## replace </span>


/<div\(\_.\{-}\)\@<=\_.\{-}> ## find <div...>
:%s:<div\(\_.\{-}\)\@=\_.\{-}>::g ## replace <div>


/<\/div\(\_.\{-}\)\@<=\_.\{-}> ## find </div>
:%s:<\/div\(\_.\{-}\)\@=\_.\{-}>::g ## replace </div>

With above a few commands, I cleaned up HTML with great result!





References


Read More...

Wednesday, April 01, 2020

Blogger: Change Background Color & Text Size

I have a blog at Blogger. Recently my friends ask me if I could change the background color and increase font size for my posts. After search on web, soon I found solutions.

Change Background Color


First go to Theme, then Edit HTML.

Expand line 9, b: skin section.





Search for "post.background.color". You will find this as variable definition.





In my Blogger, it is located at line 32: Make a copy the variable first. Then you can make change:

  1. <Variable name="post.background.color" description="Post Background" type="color" default="#ffffff" value="#353d4a"/>
  2. <Variable name="post.background.colorDeleted" description="Post Background DELETE" type="color" default="#ffffff" value="#1c1c1c"/>

Make sure the description on line 2 is not as same as description on line 1. I think that the description is a key for variables.

This variable is used for the class of post.outer





Change Font Size


Another change I would like to do is to enlarge text size of post.  This is very easy to do. Find "post-body" in HTML template



In my Programmer's blog, I could not find post-body. The size of text is defined in body class.


References




Read More...

Saturday, March 21, 2020

Story: A Traveler's COVID-19 Experience in Wuhan

Now it is pandemic critical time of COVID-19. I got an article in Chinese, a personal story of his COVID-19 in Wuhan China. I would like to share it in my programming blog. I will keep to update it with my translation as best as I can.

Personal Story of COVID-19 in Wuhan


I am a native of Wuhan and Shanghai. I got my undergraduate degree of Engineering in Huazhong University of Science and Technology in 1998. I am 43 years old. Now I run a software company in Shanghai. During my Chinese New Year's Eve in Wuhan with my family, I was suffering from neo-coronary pneumonia, ie, COVID-19, and then recovered. On January 26, 2020, I developed symptoms, and on March 14, I was confirmed to remove, and finally released from medical isolation. I have experienced the entire course of COVID-19.

As a science and tech person, I think that the COVID-19 is now a global pandemic. I try to summarize my experience and add some of the coping strategies I summarized during my sick for domestic and global friends in need as reference.

Notes on my Data

The cases covered in this article include:


  • Just myself.
  • Temporary Hospital(which is called as FangCai Hospital in Chinese) and I have 20 people in the same cabin from different administrative regions of Wuhan. My cabin number is 31st cabin of Wuhan Jianghan Fangbin Hospital.
  • The rehabilitation station was 19 people on the same floor as me, from different hospitals and cabins. Specifically, it is the 6th floor of Building 2 of a rehabilitation station in Jiang'an District, Wuhan.

My explanation:


  • The statements about specific conditions are all about me.
  • For statistics, I will indicate which data is derived from the above sample.
  • The check-in conditions for the FangCai Hospital are: at check-in, the body temperature must be below 37.5 degrees (normal body temperature) and the age must be under 65 years.
  • The admission conditions of the rehabilitation station are: cured & discharged patients who meet the official discharge standards (negative nucleic acid test for two consecutive times, normal temperature for more than 5 days, etc.). For people discharged from a number of cabins, Raytheon Hill, and Vulcan Hill Hospital, the age is not required, and some are over 65 years old.

My Sick Period

Date Description
2020/1/26 Felt fever in the morning
2020/1/29 Initial check at local community clinic, fevering not changed
2020/2/1 2nd check at the clinic, temperature remaining hight
2020/2/2 visited the specified fever hospital, and my CT showed high suspected symptom
2020/2/4 arranged nucleic acid test check by community clinic
2020/2/5 body temperature went back to normal, stayed at the norm
2020/2/6 received check result, positive.
2020/2/7 sent to Fangcai hospital by community to get isolation treatment
2020/2/29 confirmed recovery at Fangcai hospital
transfered to rehabilitation station
2020/3/4 released from rehabilitation station, back to home.
Now still need 14 days stay at home.

Key points from my own case, as well as other patient cases:


  • I started with fever symptom on 1/26 and ended on 2/5. The duration: 11 days.
  • Patients in the same cabin also have a fever duration of 1-2 weeks.
  • I started with fever, and finally were negative for all three nucleic acid tests. My discharge conditions were met, and it took 32 days.
  • Of 20 people in the same cabin, I was the 9th out of the cabin. I can roughly tell my typical indicators for my own case.

My sick development and key points


  • At the beginning stage of high temperature, I felt very cold, just like in a big room without heating. I felt like the situation of taking off cloth for shower. Even I was in the bed with covers, I was shaking cold.
  • My temperature went high at the period of 3rd to 5th day, about below 38.0. My under arm temperature was about 38.5. Before and after this period, my temperature was about 37 to 38.
  • The time of my most difficult feeling was at about 4th or 5th day. No matter I stood or were in bed, I felt heavy in my chest. It was like finishing 1000m run in middle school, could not breath comfortably. This symptom may be like what medical experts described as breath tight. After passing 2 days, my chest felt much better. At that time, it was like my body immune system was back its strength from sleep. The tight breath was improved a lot.
  • Patients with my in the same cabin all have similar feedback. With the help of medical helpers and moderate medicines, almost all of us fever went down.
  • There are 20 patients in one cabin. After our body recovered to normal, basically none one showed fever except 1-2 people, who had fever 2 days before their coming. After treatment and caring, later they did not show any fever.
  • During my fever initial days, I felt my body muscle sore and pain. After that, the symptom seems much better. After fever was gone, I have not felt muscle issue any more.
  • Since the date I was in cabin, I got measurement of blood oxen level from my fingers and the number was good relatively, among 96-99%. Only a few were 93 or 94%. Nurses took measurements 4 times daily, during 22 days.
  • After I was in cabin, I could tell my lung infection improving and ease, and I felt infections carried out by expelling sputum.
  • During the period of 2nd to 15th of my fever, my cough was very obviously, with sputum. During the highest temperature of 3 days and 2-3 days afterwards, I could see blood threads in my sputum (not clog, I guess it may be from my lung damaged tiny vessels). After 2 days in cabin, my coughing was gone. Several days later, sputum was much less, and then stopped.
  • During my stay in rehabilitation station out of cabin, we were in isolation stage. I stepped up to 6th floor. I felt breathing heavy(short break and heavy). Patients in the same floor had the same feeling. For reference, I was up to stairs every day during Aug to Sep in 2019. My speed up to 24 floors at about 5 minutes 20 seconds. I repeated 4 times (total to 96 floors), two groups in the morning and afternoon.
Cause

Unfortunately, I could not find out why for the moment.

When I was back to Wuhan, the disease were found in many places. I was very cautious and avoid out unnecessary, not contact people in large crowd. However, I was still caught the disease. I have 20 years senior programming experience, as well as many years of management and operations. My profession behave is very caution. I am with in top 1% in China. My case of COVID-19 only explains that this one is very hard to normal people to avoid. Many media news saying that it was spread by entering eyes, from shoes bottom were not enogh. I want to say that if you try to not getting this virus infection, you have to very very careful in everywhere, otherwise noway. Any careless or mistake would ruin all your protection efforts.

I try to get my caught reason as follows:

A. I might be infected by standing on street to have my breakfast (twice, about 20 minutes each time)
B. I was shopping (one time, about 30 minutes)
C. I was walking in our community area (3 times, 1 hour each time)
D. Our family build had some infected people. I might get caught during the time I was in elevator when I dump wastes (4-6 times a day, about 5 minutes)

My analysis

In all those cases, A, B, C I was with my daughter; D only myself.

My parents tested negative after my result was confirmed. My daughter was not infected. Only I was infected.

Based on above analysis, the most possibility is D.

Based on patients I was with in cabin:

  • They were in cabin and rehabilitation station. Some were veterans. They have very good body, and they exercise a lot. They still were infected.
  • Some are office workers, and they love exercise. Some got COVID-19 and passed away very quickly.
  • Based on some news, there are some wellness trainers caught COVID-19 and passed away.
My conclusion:

  • This virus is very easy to spread. Careless protection would not work.
  • The infection time is very short, may be in just minutes.
  • Don't go to area of crowd people, the risk would be very high.
  • Be very careful in closed area such as elevator. 
  • Choose to go to stairs if building is not too high, however, the stairs are also closed area. It may not safe neither.
  • People with regular exercise and good health may also get infection. It seems that virus only infect weak people.
CT Images

See Chinese version for CT images. From the image, there are some cloud in clear lung, as I marked as red.

Medical experts summarize those area as cloud and unclear area. These area maybe infected.

Clinic medical person examined my CT image, and said very positively that this was typical case, 90% COVID-19.

CT image after removed

Unfortunately all films would have to sanitized and they were all collected back. When I was out of cabin, I could not take photos. I can only simply say that all the cloud area are disappeared or much less, with only small spots. Doctors from cabin said that this is called as absolved by itself.

Here is another more straightforward comparison pictures (see tree pictures in Chinese article).

Treatment of COVID-19

 The treatment is in two stages, before cabin, and in cabin. In rehabilitation station, the condition is simple and no treatment service were provided.

Up to the time being, there is no official announcement of effective treatment medicines. I am not medical expert, nor I have any medical background. Therefore, my personal views may misleading you. Here I only objectively choose the treatment medical helpers provided for me, as for your reference. Please note that any medical treatment is only for specific case, and cannot be applied as general. Follow your medical doctors instruction when apply medicine.

During my treatment, the basics what I did are:

  1. keep positive attitude
  2. trust medical export's ability and professional skills, follow their advice to take medicines
  3. corporate with nurses routine checks and instructions
Treatment in cabin

Before cain, my treatment was mainly to follow medical instructions to take medicines.

During my community visits, I was not identified if I was normal fever or COVID-19. My treatment was mainly to reduce fever. I took fever medicines, anti-infection medicines, Lianhua medicine for ease virus. Because those methods were not for COVID-19, my fever not improved.

After that period, medical export in community realized that normal medicine seems not working. They decided to check if I was in COVID-19, and sent me to specified Wuhan Hospital to check.

At the hospital, I was determined mostly likely as COVID-19 based on CT image. They my treatment was focused on the virus. My personal feeling was that the result was very obvious. I started to take medicine on Feb 2. On Feb 5, my fever was basically released. See pictures of medicines (in Chinese article).

The last two are most effective. After taking with hotter, I felt a little bit sweat afterwards. I got those medicines from Hankou Hospital. All those medicines are within medical insurance.

Treatment in cabin

The treatment in cabin is the mixture of Western and Chinese medicines.


  • On the 1st date in cabin, doctors described us normal anti virus medicines (such as Abidol), as well as Chinese herb medicine(Lianhua anti virus capsues).
  • One week later, based on national announcement of medical treatment, we took the 2nd description, 2 bags daily, patient made decision to take or not.
  • 10 days later, doctors advised us to stop western medicines. We continued 2nd plan, 2 bags daily. They also provided more milk and other nutritions.
As I mentioned above, after I was in cabin, my fever was gone and blood oxygen level back to normal. With much less symptoms and the continuation of medicines I did not seem obviously.

Medical Expenses

My house registration and insurance are belonging to Shanghai. The expense before COVID-19 was on myself, in total 1983.42.

Date Hospital Item Fees Sub
2020/1/29 Community Clinic Diag fee 20.5
Medicine 227.45 247.84
2020/2/1 Clinic Diag 20.5
Medicine 186.62 207.12
2020/2/2 Hankou H. Reg free
Blood check 449
CT 359
Treatment 36
Med 346.98 1190.98
2020/2/7 Hankou H. Med 337.48 337.48
Total: 1983.42


I purchased commercial insurance, and I claimed it after I was released. My insurance paid 60% of my claim (about 1190yuan). For remaining amont (about 790yuan), I will check it when I get back to Shanghai. I think that it may be covered by normal insurance coverage at outside locations.

All my cabin and rehabilitation fees, all treatment, check, CT, food, daily expenses could be free. Up to the time being, I have not paid for those. I have not been asked to pay my cabin fees, nor any forms. However, I am not sure if my Shanghai insurance would refuse any payments. If any, I would list them and let my friends know.

Nutrition to COVID-19 Patients

For COVID-19 infection, nutritions are needed for patients to help them to quickly recover. I have the following list about nutrition concern:


  • Cooked eggs, 1 or 2 for breakfast and. There are rich nutritions in eggs, with protein. This will provide sufficient bullets for body to fight virus. At cabin and rehabilitation, at least one boiled egg is supplied.
  • Chicken soup. Hot soup helps to bring body strength back, help to sweat. With some salts, it adds electrolytes.
  • Balanced lunch. noon and evening meals in cabin and rehabilitation are supplied based on nutrition recommendations. Unfortunately I could find resources about it at that time. Based on my observation, there are meat, chicken, fish and shrimps for proteins, and sufficient vegs.
  • Seasonal fruits to supplement vitamins, helping to fight free-radicals.
  • Milk and sour milk, as protein and calciums supplements.
  • Small meals. small ones are almost as same as noon and evening meals, not much variations. In order to help patients to recover quicker, patients ate a little more than normal.
Because of different tastes among individuals, my observation is based food in Wuhan food style. Other places should refer to local nutrition experts recommendations.

Personal Supply Preperation

how much to prepare?

Based on my own observation, more people are less severe patients, and their treatment period is about 30 days. Taking isolation into consideration, it should prepare personal supplies for 60 days.

Basic supply

Location administrations provide guidelines for supplies, including:

  1. sufficient food: meals, vegs, meat, eggs, frozen foods, and others.
  2. cleaning products, hand gel (or 75% alcohol), soap, and others, one package for one person in a family.
  3. masks, sufficient for use
  4. sanitizers, carbon dioxide pills, 84 disinfectant, former is better to long time storage.
  5. home used medical equipments, temperature measure device, finger oxygen measure device, blood pressure measure device, and others.
  6. sufficient medicines for chronic illness if you are depend on them, such as high pressure, diabetes, insulin injection devices.
  7. toilet and hygiene paper.
Others

Besides above recommendations, based on my own and other patient cases, you may consider to prepare following supplies.

  1. strongly recommend to bring some physiology books, basic or middle levels. They will help you pre, during, and post periods.
  2. if you don't have insurance, you should consider to buy some health insurance. Pay attention to starting date of insurance.
  3. personal care products, at least 2 sets, such as finger nail cutter, shavers, swabs.
  4. women hygiene products, at least for 2 months.
  5. baby supplies if you have baby
  6. Hair cutter
  7. charger and wires
  8. medicines for eyes, such as erythromycin eye ointment, ofloxacin drops. 
  9. paper, pen and notes.
  10. several sets of one time use rain coat. if passing disinfection spray, normal rain coats are good enough.
  11. fresh preserve bags
  12. one cell, optional
  13. oxygen breath machine for senior people, about 3000 yuan cost, optional
  14. eye protection glasses, optional
  15. bicycle or electric slide board, for shot distance emergency use

Supplies for isolation

following supplies are very useful if being isolated:


  1. swissarmy utility. This device can be used to peel fruits, cut plastic bags, and fixing small items. This is really a handy device. If you don't have, you can bring fruit peeler or knigh. Those tools were allowed duing my stays. Personally, I think they are very useful.
  2. charger and wires
  3. one thermal cup and one cub, for taking medicines or cooling waters.
  4. paper, pen, and note books.
  5. carryon computer. The period of isolation was very boring. The laptop may help you to spend times.
  6. earphone plugs and eye covers. Those items were really helpful for sleeping and quick recovery. If you cannot sleep in short time, those items are good for you.
  7. toilet paper. Normally all stations have papers, but you may find it helpful in emergency.
  8. slipers. One time use or normal ones are good and convenient. But you should be careful when floor are wet or slippery (wash room, toilets), very dangerous there.
  9. personal care items such as nail cutter, shaver, and swabs.
  10. women use items
  11. a lots of fresh preserve bags, large size and thick ones.
  12. bring a book. you can read, or use it to cover convenient noddles, or as seat pad, many usages.
I recommend you to prepare those supplies now. Prepare two sets, one for you and one for family.

Self Psychological Adjustment and Recovery

I was very serious to read psychological books, on how to cope with COVID-19. Some one already provide a solution: the killer is not virus, but the panic and anxiety by the virus.

In case of being caught by the virus, either you or your friends(you may skip this section if you not by the virus), my personal self psychological adjustment for COVID-19 is as follows. I use the title of a well-known book as this section header. I think it can be also called as self-cultivation of COVID-19 patients.


  1. I agree with psychological release, instead of intervention. These two methods, for people who don't know, may think they are the same. In fact, they are very different in reality.
  2. No matter how long in treatment or isolation, or self status suddenly falling to bottom, you should always keep optimistic. Try to adapt to it, and don't just complain. If possible, try to change your context.
  3. Tell out when you cannot hold things. You should use simply and clear words to tell direct administrators, or relevant, or people who has influence. Actually, every one is willing to help you. Communication is necessary. Don't hesitate, depressed, or would bother others.
  4. The most important thing to do is to maintain good sleep.
  5.  After 8:00pm, you could play games, don't watch mass media news about the virus, which may affect your sleep.
  6. Image a way to guide your to sleep. What I did to watch math of university level. I remembered that I would go to sleep when I saw those questions. Now I could use this strategy. You could learn something when you cannot sleep, or fall in sleep.
  7. Friends around you all would like to talk. Try to talk to them. This could help you to ease stressed mood. Keep away 1 meter away, just remember this. Every one should wear masks. Keep further away if not with mask.
Conclusion

I close my strategies towards COVID-19. I hope every one have most careful protection measures. It is better not being caught by the virus. In case of you infected, I hope you will overcome fear thoughts, be positive.

I think I am a ordinary person, just like you. I have managed to pass over this journey and fully recovered, same will be you. Be strong!

I hope that my experience and this summary could help you. If you have any questions, or want to know more, please leave your comments. I will try my best to answer your questions.


References



Read More...

Wednesday, March 04, 2020

Conditional Compilation in Xcode

Recently I have interest in C/C++ #ifdef macro features in Swift. The main reason is that I have some debug codes through out my project for test and debug purpose. For example, I like to add deinit destruction with print() codes in classes to test memory leaks. Since those destructors have no purpose to clean up resources, I have to comment out them in production compilation.

In Swift, there are some conditional compilation features to including or excluding block of codes. For example, the following codes using #available to test if the current iOS matches required version.

if #available(iOS 11.0, *)

Further investigation, I find out that Swift does support #if statements to provide conditional compilation. The following are steps to implement the feature.

Define Custom Compilation Flags


The first step is to define customized complication flags in Xcode project. In the section of Build Settings, find Swift Compiler - Custom Flags (make sure All and Combined are enabled on top tab bar).



Then, you can add custom flag variables. Here are two examples of DEBUG_PRINT and DEBUG_DEINIT. For each flag, add -D before it, like "-D DEBUG_DEINIT -D DEBUG_PRINT"



Note: in the picture, I defined those two with _X as suffix to disable them. If I want to enable them in compilation, I remove _X.

Use Custom Compilation Flags in Swift


To use #if feature, it is quite straightforward. For example, there is the conditional compilation block for destructor:


  1. // MARK: - CTOR
  2. #if DEBUG_DEINIT
  3. deinit {
  4.  Logger.debug() {
  5.    String("\(CopyMoveViewController.className) deinit")
  6.  }
  7. }
  8. #endif
and here is an example of conditional compilation block for some codes:

  1. class Logger {
  2.  ...
  3.  static func debug(_ message: () -> String) {
  4.    #if DEBUG_PRINT
  5.    print(message())
  6.    #elseif DEBUG_DEINIT
  7.    print(message())
  8.    #endif
  9.  }
  10. }

Now I don't need to comment out some debug codes when I need to compile my project to production release target. The only thing I need to do is to disable those flags in my Xcode project file.

References



Read More...

Wednesday, January 08, 2020

Update to Xcode 11.3

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.


I had to restore back to 11.1 version. Fortunately, I have Time Machine backup. From there, I restored Xcode 11.1.

Xcode 11.3 was released, but I did not update right away. Until I tried to compile my project to my iPhone with iOS 13. I got message that I had to move up to newer Xcode supporting iOS 13. I have no choice to move  on.

Update from App Store is also a pain. I tried for several days to update but I got failure each time. There is no reason given, and each time it took long period to download package, 7.8GB. That was really frustrating.

Yesterday a idea came up to my mind. Why not to go to Apple developer site to get Xcode? There must be Xcode 11.3 package just for download only. I went to the site and Xcode.xip is in the section of More(Beta, Release and More 3 sections). This makes me update much easier because it is the straight download.

After downloading, I clicked on the package. Soon I got a message of "not enough space on destination". That's why. The disk space is always problem on MacBookAir/Pro. What I did is to move out existing Xcode from Application to external disk. Finally I got Xcode 11.3 successfully installed!

So far, I have no issues with this version, and I could run my app on my iPhone for testing.

Read More...

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...

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




Read More...

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/DeviceSupport


To


/Applications/Xcode/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport

Now I can run my codes from Xcode 9.4 to my iPhone 5s device.

What's adventure and life-saving experience!


References


Read More...

Wednesday, October 03, 2018

Python script: MapIt.py


Based on an example, script of mapIt.py, from the video of Automate the Boring Stuff with Python, I figured out that the codes should be changed in Mac OS X, as I mentioned that there are multiple versions of python in Max OS in my previous blog.

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:


  1. #! /usr/bin/env python3
  2. import webbrowser, sys, pyperclip
  3. sys.argv  # example ['mapit.py', '870', 'Valencia', 'St.']
  4. address = 'Home'
  5. if len(sys.argv) > 1 :
  6.    address = ' '.join(sys.argv[1:]) # ['870', 'Valencia', 'St.']
  7. else :
  8.    address = pyperclip.paste()
  9. # https://www.google.com/maps/place/<address>
  10. 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:

...$ python3 Programming/py/mapit.py Park Ave 83 St New York

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 from terminal, or from Spotlight, without specifying python3. For the case of terminal, first I have to make the script executable with the following commands:

...$chmod a+x ~/Programming/py/mapit.py

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:

  1. PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}:/Users/dchu/Programming/py"
  2. export PATH

With above setup ready, now I can run the script anywhere in terminal:

...$ mapit.py Donggaodi Hongxing St Beijing

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:

  1. ...$ cd ~/Programming/py
  2. ...$ 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


Read More...