Module not found while compile with Swift Package Manager


We have a framework named “LibA” supported SPM.
There is class can be use and override outside:

open class Alert: UIViewController {...}

In my app’s project, I added LibA with Swift Package Manager (Xcode 11 beta 4), it would be compiled as static lib by default.
And there is a framework target named “FrameworkB” in the project, it would be compiled as dynamic lib and it would be embedded to the app.

An extension defined in FrameworkB, and it would be called by other public class:

extension Alert {
  func show() {...}

I would got compile error in FrameworkB-Swift.h:

@import LibA; <--- Module 'LibA' not found

After remove the extension, implementation show() by other way, the error was gone.

Other attempt

  • The error would present again, if I did:
    • To change LibA.Alert as public.
    • To mark show() as fileprivate.
  • If I made subclass extend Alert as internal or private, compilation would pass, but do not make subclass as public or open.


Extension of Alert (subclass of NSObject) would mark the LibA should be import in FrameworkB-Swift.h, subclass of Alert with public or open would made same thing too, even if I can found nothing about Alert in FrameworkB-Swift.h.

I think there is bug in Xcode 11 beta 4.

Xcode Validate failed with framework Code-sign Error


My iOS app contains two custom swift embed framework, there named FWA and FWB here, and some 3rd party embed framework.

I compiled them as universal framework with bitcode, and archived my app.

I got error while I validating the archive –

2016-09-09 01:50:58 +0000  /var/folders/8d/6t4zhl296lx7_1nlg7qt5_j40000gn/T/XcodeDistPipeline.CDC/Root/Payload/ replacing existing signature
2016-09-09 01:50:58 +0000  /var/folders/8d/6t4zhl296lx7_1nlg7qt5_j40000gn/T/XcodeDistPipeline.CDC/Root/Payload/ invalid resource directory (directory or signature have been modified)

Only FWB got this, FWA is fine.

Both them have same code-sign settings: iOS Developer, and same Provisioning Profile: Automatic.

Finally, I changed FWB’s Provisioning Profile as iOS Team Provisioning Profile: *, validate passed.

Maybe Xcode cannot find Provisioning Profile for FWA, so it is code-sign free framework.
However Xcode chosen incorrect Provisioning Profile for FWB, since it have similar bundle id with my app.

Call and embed C/Obj-C code in Swift Framework


Since Xcode 6, we can create dynamic frameworks with swift language running on iOS 8.

In my swift framework, I have to implement some functions with C or Obj-C code like compression. As found from searching, maybe I can use Bridge Header to use zlib and some obj-c libs. However, Xcode reported error, in framework I can’t use bridge!

I’d tried defined an unzip protocol in framework, implement it in my app project, set to framework class. But I felt this is not best way.

In next searching, I found @asmname. IT IS WOUNDERFUL NEWS!
I can define some C function to return result I want, like this:

In zip.m:
id zipData(NSData *data, BOOL compress) {}

In Zip.swift:
// @asmname did changed to @_silgen_name since swift 2.2
@asmname("zipData") func c_zipData(data: NSData, compress: Bool) -> AnyObject

class Zip {
  func zipData(data: NSData, compress: Bool) -> (NSData?, ErrorType?) {
    let result = c_zipData(data, compress: compress)
    if let data = result as? NSData { return (data, nil) }
    return (nil, result as? ErrorType?)

It can WORK! But … App crashed … EXC_I386_GPFIT

Then I changed scheme setting, open NSZombie, tip me sending message to released object – [NSInlineData release].

I think the reason is –
Since ARC, in zip.m, after zipData() returned, the NSData would be called release by Cocoa.
After Zip.swift got the NSData object (or NSError), it don’t know the object should be retain first, but it would release it.

So I changed swift code:

let result = Unmanaged<AnyObject>.passRetained(c_zlibData(data, compress: compress)).takeUnretainedValue()

I guess Unmanaged.passRetained() just like shared_ptr in C++, it would retained once, after swift code needn’t the object, ARC would make retainCount from 1 to 0.

And I was tried to use passUnretained().takeRetainedValue(), the code would crash in next line.

OK, problem solved, I shall make my best framework happily right now~

error relocation overflow in R_ARM_THM_CALL


I got many error like this while compiling cocos2d-x game (cocos2d-x 3.3 + quick, Android NDK r10d).

These error shown by many cocos2d-x class like UILayout.cpp or CCHttpClient.cpp, many method from web is that add LOCAL_ARM_MODE:=arm into, but it is nothing affect.

Finally, I try to change, change head to this:
APP_STL := gnustl_static
NDK_TOOLCHAIN_VERSION=4.9 # it was clang.

After that, compile did passed.

Resize or repirtation USB HDD on Mac

  • Keep away from the app named StellaPartitionManger.
  • Half function of Disk Utility can only worked on recovery mode.

3 days before, I felt I spend more disk space (B) on my 1T USB HDD to unused partition:

A 50G ntfs, B 250G ntfs, C 500G hfs+, D 120G hfs+

1st night, I merged B & C. There is goes well copy all of file to volume C, and removed volume B.


2nd morning, I found an OS X app named StellaPartitionManager and looks well, then begin to resize C, let it scale to most space it could.

StellaPartitionManger still worked whole day from 10AM to 9PM, and Not finished! No progress bar! Only status description: Moving blocks.
I should go home now! Should I wait it whole night? No!
Finally, I terminated it, and found no data lost… What the hell StellaPartitionManger did…

At home, I did backup all data, tried to repartition all volumes with StellaPartitionManger, but problem coming.
While StellaPartitionManger finished operate, OS X could not identity the disk!
What did you done, StellaPartitionManger!

Disk Utility couldn’t erase any volume, couldn’t repartition on the disk.
And I tried plug it to a Windows computer, did repartition, OS X couldn’t identity it.
And I tried to use root permission on Terminal open Disk Utility or use disutil command, got same error tip.
StellaPartitionManger, I remembered you! Get out my sight!

In the last morning, I try to restart Mac and press command+r enter recovery mode, open Disk Utility.
It worked now! My dearest volumes come back!

GXUI – GUI for go from google


Google released open source GUI library based on OpenGL – GXUI.

Feature from source code –

  • Contains many components like Button, TextInput, Tree and more.
  • There are tree adapter specific class.
  • Theme change, default for dark.
  • Based on OpenGL.
  • Easy cross-compiling with C extension.

Install on Mac

I’m using Mac OS X 10.10.3 beta and Golang 1.4.

First of all, install GLEW into system. Download newest GLEW from SourceForge. Then run:

$ tar xvzf glew-20150124.tgz
$ cd glew-1.11.0
$ make
$ sudo make install

Ignore compile warning, and run:

$ go get
$ go get
$ go get
$ go get

While installing freetype, there maybe an error – exec: “hg”: executable file not found in $PATH
run this or browse Mercurial Download site for other platform.

brew install mercurial

After all commands did finished, enter $GOPATH/src/gxui/samples and run any sample app.

$ cd $GOPATH/src/
$ go run polygon

And you may found the polygon is about 7.1MB after you build it, there is amazing size!
The reason is GXUI use golang use so little dependent library: (removed compatibility version)

$ otool -L ./main

Most of them are system libraries.

Repost from Qiita.

Facebook SDK could not show invite or request dialog


We are testing invite and request with Facebook SDK in our game for company, and we used FBWebDialog on iOS.

Some of request is worked, friend could received on Facebook, only request live could not, the dialog hide too fast to click “send” button.

I searched and found too many FAQ, Q&A, and found nothing, Facebook document does no help to me.
Finally, when we testing same feature on Android, we found the reason –

Facebook limited invite or request title must less than 50 characters!

OK, no program issue, just title text too long …

Facebook SDK无法显示邀请或请求对话框

我们要在公司的游戏里测试用Facebook SDK邀请好友与向好友请求,在iOS上用FBWebDialog。





Launch sequence for cocoa (iOS and OS X)


First, call main(), and call UIApplicationMain(), in there it done these –

  • Create instance of UIApplication.
  • Create delegate instance for UIApplication – YourAppDelegate.
  • Open message loop, notify YourAppDelegate while system event.
  • Create instance of UIWindow (extend by UIView), set as window property for YourAppDelegate.
  • Load Info.plist then find storyboard out.
  • Load storyboard and create root view controller (point by white arrow).
  • Set the view controller above as rootViewController property for UIWindow.
  • Create and add rootViewController.view as sub view to UIWindow, and show UIWindow.

Continue reading