iOS上如何製作自己的Framework呢?

來源:互聯網
上載者:User

iOS上如何製作自己的Framework呢?(不是靜態庫)

請看stackoverflow上的提問:

http://stackoverflow.com/questions/4065052/how-to-build-a-framework-or-library-for-other-developers-the-secure-way

解決辦法

1,通過命令列指令碼

http://www.cocoanetics.com/2010/04/making-your-own-iphone-frameworks/

由cocoa的Framework演變而來

2,通過hack  bundle

http://www.cocoanetics.com/2010/05/making-your-own-iphone-frameworks-in-xcode/

這種方法有熱心的同學做了中文翻譯 

http://www.cocoachina.com/bbs/read.php?tid-75680.html

但是需要製作2個framework,分別對應於simulator和device

這種方法這裡也有詳細介紹 http://db-in.com/blog/2011/05/creating-universal-framework-to-iphone-ios/

3,使用別人的模板

https://github.com/kstenerud/iOS-Universal-Framework

這個算是集大成吧。當然作者有說明,這個也是假的,並不能象SDK內建的framework那樣自如使用

而code google上的pldatabase framework是可以象SDK自己的framework一樣,一個framework同時運行在模擬器和真機上的

http://code.google.com/p/pldatabase/

有待研究,以後再來補充

補充:

pldatabase framework 也只是產生2個靜態庫(.a)然後通過lipo合并起來,但是這已經很好了。

Lipo Binary 中的指令碼如下:

FRAMEWORK="${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework"

lipo \
"${BUILD_DIR}/${CONFIGURATION}-iphoneos/libPlausibleDatabase-iPhoneOS.a" \
"${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/libPlausibleDatabase-iPhoneSimulator.a" \
-create -output "${FRAMEWORK}/Versions/Current/${PRODUCT_NAME}"

cd "${FRAMEWORK}" && ln -sf "Versions/Current/${PRODUCT_NAME}" ./

看來上面的方法沒有產生真正意義上的Framework,所謂的Framework不是hack bundle就是 hack
static lib

至於第二種方法為什麼可以實現,因為Framework其實也是一個bundle
(a structured directory),

可以參照apple的官方說明 http://developer.apple.com/library/mac/#documentation/General/Conceptual/DevPedia-CocoaCore/Framework.html


詳見:http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WhatAreFrameworks.html%23//apple_ref/doc/uid/20002303-BBCEIJFI

What are Frameworks?

framework is a hierarchical directory that encapsulates shared resources, such as a dynamic shared library, nib files, image files, localized strings, header files, and reference documentation in a single package. Multiple applications can
use all of these resources simultaneously. The system loads them into memory as needed and shares the one copy of the resource among all applications whenever possible.

A framework is also a bundle and its contents can be accessed using Core Foundation Bundle Services or the Cocoa NSBundle class. However, unlike most bundles, a framework bundle does not appear in the Finder as an opaque file. A framework bundle is a standard
directory that the user can navigate. This makes it easier for developers to browse the framework contents and view any included documentation and header files.

Frameworks serve the same purpose as static and dynamic shared libraries, that is, they provide a library of routines that can be called by an application to perform a specific task. For example, the Application Kit and Foundation frameworks provide the programmatic
interfaces for the Cocoa classes and methods. Frameworks offer the following advantages over static-linked libraries and other types of dynamic shared libraries:

  • Frameworks group related, but separate, resources together. This grouping makes it easier to install, uninstall, and locate those resources.

  • Frameworks can include a wider variety of resource types than libraries. For example, a framework can include any relevant header files and documentation.

  • Multiple versions of a framework can be included in the same bundle. This makes it possible to be backward compatible with older programs.

  • Only one copy of a framework’s read-only resources reside physically in-memory at any given time, regardless of how many processes are using those resources. This sharing of resources reduces the memory footprint of the system and helps improve performance.

Note: Frameworks are not required to provide a programmatic interface and can include only resource files. However, such a use is not common.

The Darwin layer contains many static and dynamic libraries but otherwise, most Mac OS X interfaces are packaged as frameworks. Some key frameworks—including Carbon, Cocoa, Application Services, and Core Services—provide convenient groupings of several smaller
but related frameworks. These framework groups are called umbrella frameworks and they act as an abstraction layer between a technology and the subframeworks that implement that technology.

In addition to using the system frameworks, you can create your own frameworks and use them privately for your own applications or make them publicly available to other developers. Private frameworks are appropriate for code modules you want to use in your
own applications but do not want other developers to use. Public frameworks are intended for use by other developers and usually include headers and documentation defining the framework’s public interface.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.