You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by zs...@apache.org on 2018/12/14 04:01:50 UTC

[incubator-weex-site] branch draft updated: Update extend-ios-with-swift.md

This is an automated email from the ASF dual-hosted git repository.

zshshr pushed a commit to branch draft
in repository https://gitbox.apache.org/repos/asf/incubator-weex-site.git


The following commit(s) were added to refs/heads/draft by this push:
     new 6270bbb  Update extend-ios-with-swift.md
6270bbb is described below

commit 6270bbbf787d0d00a2562f1d7928201c68607e20
Author: zshshr <zh...@gmail.com>
AuthorDate: Fri Dec 14 12:01:46 2018 +0800

    Update extend-ios-with-swift.md
---
 docs/guide/extend/extend-ios-with-swift.md | 72 +++++++++++++++++-------------
 1 file changed, 42 insertions(+), 30 deletions(-)

diff --git a/docs/guide/extend/extend-ios-with-swift.md b/docs/guide/extend/extend-ios-with-swift.md
index c6e635f..5d39a9f 100644
--- a/docs/guide/extend/extend-ios-with-swift.md
+++ b/docs/guide/extend/extend-ios-with-swift.md
@@ -1,17 +1,28 @@
+---
+title: Extend iOS with swift
+type: guide
+group: Extend
+order: 6.4
+version: 2.1
+---
+
 ## Swift In Weex
 
-[Swift和Objective-C](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-ID122) 混编
+[Swift and Objective-C](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-ID122) mix-up
+
+a complete [demo](https://github.com/acton393/WeexSwiftSample.git)
 
-参考完整 [例子](https://github.com/acton393/WeexSwiftSample.git)
+### extend module using swift
 
-### 使用 Swift 进行 module 扩展
+ As we export moudle method using macro and calling in runtime, so we can extend module using swift by `extension` `bjective-C` class.
+ > You can also finish extending module by write an category for swift class in Objective-C class.
 
-因为 module 暴露 method 是通过`Objective-C`宏来做的,调用的时候是通过反射,所以Swift扩展 module 通过`extension` `Objective-C`的类。
-- 新建 `WXSwiftTestModule.h/m` 和 `WXSwiftTestModule.swift`文件, 在新建Swift文件的时候会提示
+- new `WXSwiftTestModule.h/m` and `WXSwiftTestModule.swift` file ,you will get a tip as follow during the creation
   ![img](http://img3.tbcdn.cn/L1/461/1/b2ed3ee4a966953c0f98a17f34f6f05e7c91cc6b)
-  选择 `Create Bridging Header`, 因为我们要在 Swift 中访问 `Objective-C` 的一些类,正是通过这个 header暴露 OC 的类给 Swift,header 格式为 `yourTarget-Bridging-Header.h`,我这里创建完header文件名称为:`WeexDemo-Bridging-Header.h`
-- `WXSwiftTestModule.h/m`中实现
-  - WXSwiftTestModule.h 中
+  choose `Create Bridging Header`, as we need to access method in `Objective-C` in swift file, and the `Bridging header` can help us. And the format name of the header file is `yourTarget-Bridging-Header.h`, and mine is `WeexDemo-Bridging-Header.h`.
+
+- implementation in `WXSwiftTestModule.h/m`
+  - WXSwiftTestModule.h
     
     ```
         #import <Foundation/Foundation.h>
@@ -22,33 +33,33 @@
         @end
     
     ```
-  - WXSwiftTestModule.m 中
-    
-    WeexDemo-Swift.h 这个文件需要编译一下才可以搜索到,具体的路径
+  - WXSwiftTestModule.m
     
+    you can search WeexDemo-Swift.h after building your project, Xcode will generate this file for us.
+
+    for simulator the file path may be: 
     ```
     weex/ios/playground/DerivedData/WeexDemo/Build/Intermediates/WeexDemo.build/Debug-iphonesimulator/WeexDemo.build/DerivedSources/WeexDemo-Swift.h
     ```
-    
-    路径具体需要根据自己工程而定
-    
+    export method define in swift file.
     ```
         #import "WXSwiftTestModule.h"
-        #import "WeexDemo-Swift.h" // Swift类和方法 被 `Objective-C` 识别需要导入
+        #import "WeexDemo-Swift.h" // you need to import the header to make Objective-C code recognize the method defined in swift file.
     
         @implementation WXSwiftTestModule
-        #pragma clang diagnostic push //关闭unknow selector的warrning
+        #pragma clang diagnostic push //forbid unknow selector warrning
         #pragma clang diagnostic ignored "-Wundeclared-selector"
     
-        WX_EXPORT_METHOD(@selector(printSome:callback:)) //Swift 中定义的方法,XCode 转换成的最终的方法名称,在`WeexDemo-Swift.h`里面查看
-    
+        WX_EXPORT_METHOD(@selector(printSome:callback:)) //method name in Swift, you can get the final method name in `WeexDemo-Swift.h` as the convert of Xcode.
+
         #pragma clang diagnostic pop
     
         @end
     
     ```
-- Swift 中实现 
-  扩展 OC 的类 `WXSwiftTestModule`,增加了一个方法,这个方法就是我们要暴露出来,在 js 中可以调到的
+- in Swift
+  make an extension for Objective-C class `WXSwiftTestModule`, add a method, and then export it in Objective-C, then we can use it in javaScript.
+
   - WXSwiftTestModule.swift
     
     ```
@@ -61,8 +72,9 @@
         }
     ```
     
-    `WXSwiftTestModule` 和`WXModuleCallback` 因为是 OC 的,需要在 `WeexDemo-Bridging-Header` 中暴露
-  - WeexDemo-Bridging-Header.h中
+  we need to expose `WXSwiftTestModule` `WXModuleCallback` in `WeexDemo-Bridging-Header` as our `Objective-C` need to access them
+
+  - WeexDemo-Bridging-Header.h
     
     ```
     //
@@ -71,18 +83,18 @@
     #import "WXSwiftTestModule.h"
     #import "WeexSDK.h"
     ```
+
+    by far we have finished our module using swift.
     
-    至此这个使用 Swift 开发的简单的 module 已经完成
-    
-  ### module 使用
-  - 注册 module 
-    
+  ### module usage
+  - register module to WeexSDK
+
     ```
     [WXSDKEngine registerModule:@"swifter" withClass:[WXSwiftTestModule class]];
     
     ```
-  - 前端脚本中用法
-    
+  - front-end usage
+
     ```
       <template>
           <text>Swift Module</text>
@@ -99,4 +111,4 @@
     
         };
       </script>
-    ```
\ No newline at end of file
+    ```