Saturngod

What's on my mind

Swift Is Fast Now

Today, I update the Xcode 6 Beta 3 and retest the bubble sort that I wrote yesterday. In Beta 3, bubble sort is done in 11 miliseconds in Debug Mode. Before it done in 14 miliseconds. After that I changed to the Release Mode and run it. It done in the 0.15 miliseconds. Yes, this time swift is faster than Objective-C now. In objective-C , it done in 0.28 miliseconds.

Swift Programming Language book has been updated and you need to update it.

Changes in Xcode 6 beta 3 for Swift are

  • Array in Swift has been completely redesigned to have full value semantics like Dictionary and String have always had in Swift. This resolves various mutability problems – now a ‘let’ array is completely immutable, and a ‘var’ array is completely mutable – composes properly with Dictionary and String, and solves other deeper problems. Value semantics may be surprising if you are used to NSArray or C arrays: a copy of the array now produces a full and independent copy of all of the elements using an efficient lazy copy implementation. This is a major change for Array, and there are still some performance issues to be addressed. Please see the Swift Programming Language for more information. (17192555)!
  • The Array and Dictionary “sugar” syntax has been redesigned: You now declare arrays as [Int] instead of as Int[], as shorthand for Array. The old syntax made sense when arrays had semantics closer to C arrays, but would be misleading with the new value semantics approach. Along with this, Dictionary syntax has improved so that [Key:Value] is treated as sugar for Dictionary. Both of these are now consistent with each other and with the literal syntax used to build an array or dictionary. Please see the Swift Programming Language for more information.!
  • NSDictionary* is now imported from Objective-C APIs as [NSObject : AnyObject]. (16870626)!
  • The half-closed range operator has been changed from .. to ..< to reduce confusion and ambiguity. Now the two range operators are ..< and … for half-closed and closed ranges, respectively (17203527).!
  • nil is now a literal in the language, not a global constant of _Nil type. This change resolved a number of problems with nil; e.g. nil in a collection, nil converting to Any, etc. Types can now indicate that they are nil compatible by conforming to the NilLiteralConvertible protocol. (16951729)!
  • APIs imported from C no longer use type aliases like CInt or CFloat, which obfuscated the underlying type. They are now imported as Int32 and Float, etc.!
  • APIs imported from C that use C pointers are now imported with a much simpler API type structure which is more predictable, preserves const mutability in more cases, and preserves __autoreleased pointer information. Now you will see UnsafePointer, ConstUnsafePointer, AutoreleasingUnsafePointer, etc. Function pointers are also imported now, and can be referenced and passed around. However, you cannot call a C function pointer or convert a closure to C function pointer type.!

You can read more at here

Is Swift Really Fast ?

Apple claimed that swift is faster than the Objective-C. However, I feel is slower than Objective-C. When I writing the custom keyboard with Swift , IDE response too slow and Sourcekitservice use over 100% CPU usages. It may be the IDE bug and X-Code 6 still beta 2.

So, I tried to sort the array with bubblesort with Objective-C and Swift like following.

As the result , Objective-C done is 0.297070 miliseconds and Swift Done in 14 miliseconds. It’s so much different. So, I change the swift compiler method to Fastest and It done ine 0.5 miliseconds. Not so much different with Objective-C but still slow.

I hope, it’s a bug and apple will fix in next version of xcode 6 release. I love the Swift because it’s safer and easier than Objective-C. However, I don’t want to use if it’s slower than Obective-C at run time.

iOS 6 include new font fall back system

In iOS 5, they only search glyph for missing code at fallback.ttf . However, they changed in iOS 6. In iOS 6, they search the whole font list.

How Do I know ?

In Xcode , add MON3 Anonta 1 in info.plist (UIAppFonts).

Just used UITableViewController and add around 20 rows.

Use text like following.

cell.textLabel.text = [NSString stringWithFormat:@"လက်ရှိ နံပတ် %@",[self numberToMyanmarNumber:indexPath.row]];

We are using Myanmar Unicode and run on iOS 5 simulator.

It didn’t show font and we can scroll smoothly.

Now, let run on the iOS 6 simulator. We will see result like following

Some of the glyph are appear without declaration of the font. It can’t show well yet. But it’s a problem of not working well with some users like me. I can’t use facebook , email because I have a lot Myanmar friends and they are using and sending email with Myanmar Fonts. iOS didn’t support Myanmar Fonts but they are trying to find in all fonts. So, UITableView glitches on fast scrolling.

I hope, Apples will use iOS 5 font fallback problem for us. Myanmar , Khmer and some country didn’t use well with iOS 6 because this fall back system.

Is it best ?

Yes, it may be good for feature. Apple can support new font easily in futture and no need to put on fallback.ttf. Just add new fonts if they want to support. It easy like that in future.

Is it bad ?

Yes, it is bad for me. If apple didn’t support some language like Myanmar , Khmer , it trouble a lot in all of the apps like facebook , email , twitter ,etc.

iPhone/iPodTouch OS 3.1.2 jailbreak

I wrote about that in Mac For Us. You can read in there.