swift code by miao