fix a segfault problem in swift

Fix a segfault problem in swift (issue 52).