V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
banxi1988
V2EX  ›  iDev

Xcode Swift 项目 多 Target 共享代码经验

  •  
  •   banxi1988 ·
    banxi1988 · 2015-04-24 18:50:10 +08:00 · 3896 次点击
    这是一个创建于 3304 天前的主题,其中的信息可能已经有所发展或是发生改变。
    1. 如果跟 IB 无关的代码,直接通过控制 Target Member来实现即可
    细微的代码差别通过,预编译来处理

    2. 涉及到 IB 相关的,因为 Controller的属性中有Custom Class 属性
    及 Custom Module 属性:
    如下:
    ```
    <tableViewController storyboardIdentifier="alertTimePicker" title="提醒时间" id="8Ci-b5-XGV" customClass="NotificationTimeViewController" customModule="demo_shared" sceneMemberID="viewController">
    ```
    大部分情况下是正常,但是如果 你遇到类似如下问题:
    > Unknown class _TtC13demo_shared30NotificationTimeViewController in Interface Builder file.

    就有问题了.
    我的一个解决办法是,将多个Target都设置成同名的module name,这样无论是在哪一个Target 下编译都不会有问题

    关于第二点,
    大部分情况正常是因为正常的时候: ViewController的配置还有另外一个属性: customModuleProvider
    ```
    <viewController storyboardIdentifier="singleWeekTable" title="单周" useStoryboardIdentifierAsRestorationIdentifier="YES" id="kZ3-Y1-WuQ" customClass="WeekTableViewController" customModule="demo_shared" customModuleProvider="target" sceneMemberID="viewController">
    ```

    customModuleProvider是什么时候没有的?
    我的情况是,是, 是 (其实具体原因我也想不起来了), 好像是从一个Storyboard将 VC移动到另一个Storyboard中.

    上面折腾这么一些,还有一个原因就是, Swift不支持Static Library
    其实弄Static Library还更麻烦.

    PS: 除了将多个Target 设置成同样的Product Module Name,
    还可以将出问题的VC中的Custom Module删除, 这个时候,customModuleProvider = "target"
    这个属性就会回来了..



    有了 Target member和 预编译 Xcode Swift 项目 多Target 共享主要代码还是相当简单的.
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5767 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 03:00 · PVG 11:00 · LAX 20:00 · JFK 23:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.