iOS在Cocoa Touch Static Library使用CocoaPods
1、在XCode中新建静态库工程:DDLogLib。
2、添加对外暴露接口的头文件DDLogLibHeader.h

3、命令行进入DDLogLib目录,运行pod init,并修改Podfile

4、运行pod install,并打开DDLogLib.xcworkspace。
5、运行pod spec create DDLogLib,创建DDLogLib.podspec文件,并编辑。
# Be sure to run `pod spec lint DDLogLib.podspec' to ensure this is a
# valid spec and to remove all comments including this before submitting the spec.
#
# To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#
Pod::Spec.new do |s|
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# These will help people to find your library, and whilst it
# can feel like a chore to fill in it's definitely to your advantage. The
# summary should be tweet-length, and the description more in depth.
#
s.name = "DDLogLib"
s.version = "0.0.1"
s.summary = "A short description of DDLogLib."
s.description = <<-DESC
A longer description of DDLogLib in Markdown format.
* Think: Why did you write this? What is the focus? What does it do?
* CocoaPods will be using this to generate tags, and improve search results.
* Try to keep it short, snappy and to the point.
* Finally, don't worry about the indent, CocoaPods strips it!
DESC
s.homepage = "http://EXAMPLE/DDLogLib"
# s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Licensing your code is important. See http://choosealicense.com for more info.
# CocoaPods will detect a license file if there is a named LICENSE*
# Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
#
s.license = "MIT (example)"
# s.license = { :type => "MIT", :file => "FILE_LICENSE" }
# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the authors of the library, with email addresses. Email addresses
# of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
# accepts just a name if you'd rather not provide an email address.
#
# Specify a social_media_url where others can refer to, for example a twitter
# profile URL.
#
s.author = { "hu5675" => "hu5675@126.com" }
# Or just: s.author = "hu5675"
# s.authors = { "hu5675" => "hu5675@126.com" }
# s.social_media_url = "http://twitter.com/hu5675"
# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If this Pod runs only on iOS or OS X, then specify the platform and
# the deployment target. You can optionally include the target after the platform.
#
# s.platform = :ios
# s.platform = :ios, "5.0"
# When using multiple platforms
# s.ios.deployment_target = "5.0"
# s.osx.deployment_target = "10.7"
# s.watchos.deployment_target = "2.0"
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the location from where the source should be retrieved.
# Supports git, hg, bzr, svn and HTTP.
#
s.source = { :git => "http://EXAMPLE/DDLogLib.git", :tag => "0.0.1" }
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# CocoaPods is smart about how it includes source code. For source files
# giving a folder will include any swift, h, m, mm, c & cpp files.
# For header files it will include any header in the folder.
# Not including the public_header_files will make all headers public.
#
s.source_files = "DDLogLib", "DDLogLib/**/*.{h,m}"
s.exclude_files = "DDLogLib/Exclude"
s.public_header_files = "DDLogLib/**/*.h"
# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# A list of resources included with the Pod. These are copied into the
# target bundle with a build phase script. Anything else will be cleaned.
# You can preserve files from being cleaned, please don't preserve
# non-essential files like tests, examples and documentation.
#
# s.resource = "icon.png"
s.resources = "DDLogLib/Resources/*.png"
# s.preserve_paths = "FilesToSave", "MoreFilesToSave"
# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Link your library with frameworks, or libraries. Libraries do not include
# the lib prefix of their name.
#
s.framework = "SystemConfiguration"
# s.frameworks = "SomeFramework", "AnotherFramework"
# s.library = "iconv"
# s.libraries = "iconv", "xml2"
# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If your library depends on compiler flags you can set them in the xcconfig hash
# where they will only apply to your library. If you depend on other Podspecs
# you can include multiple dependencies to ensure it works.
# s.requires_arc = true
# s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
s.dependency "CocoaLumberjack"
#s.dependency "other lib"
6、新建工程DDLogLibAPP,与DDLogLib保持在同一目录,命令行进入DDLogLibAPP,运行pod init,并编辑。
# Uncomment this line to define a global platform for your project
# platform :ios, '6.0'
target 'DDLogLibAPP' do
pod 'DDLogLib', :path => '../DDLogLib'
end
target 'DDLogLibAPPTests' do
end
target 'DDLogLibAPPUITests' do
end
7、运行pod install,并打开DDLogLibAPP.xcworkspace编译。
8、在DDLogLib实现printABC方法。
DDLogLib.m
#import "DDLogLib.h"
#import "DDLog.h"
#import "DDFileLogger.h"
#import "DDTTYLogger.h"
static int ddLogLevel = LOG_LEVEL_INFO;
@implementation DDLogLib
- (void)printABC{
NSLog(@"ABC");
DDLogFileManagerDefault *logFileManager = [[DDLogFileManagerDefault alloc] init];
DDFileLogger* _fileLogger = [[DDFileLogger alloc] initWithLogFileManager:logFileManager];
_fileLogger.rollingFrequency = 60 * 60 * 24; // 24 hour rolling
_fileLogger.logFileManager.maximumNumberOfLogFiles = 7; // a weeks worth
//#ifdef DEBUG
[DDLog addLogger:[DDTTYLogger sharedInstance]];// this is log to xcode window.
//#else
[DDLog addLogger:_fileLogger];
//#endif
DDLogInfo(@"DDLog ABC");
}
@end
DDLogLib.h
#import <Foundation/Foundation.h>
@interface DDLogLib : NSObject
- (void)printABC;
@end
9、在DDLogLibAPP中调用。
#import "AppDelegate.h"
#import <DDLogLib/DDLogLib.h>
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
DDLogLib* logLib = [[DDLogLib alloc] init];
[logLib printABC];
return YES;
}
10、运行DDLogLibAPP,一切正常。
11、在DDLogLibAPP中直接使用DDLog。
#import "AppDelegate.h"
#import <DDLogLib/DDLogLib.h>
#import <DDLog.h>
#import <DDFileLogger.h>
#import <DDTTYLogger.h>
static int ddLogLevel = LOG_LEVEL_INFO;
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//app 通过静态库调用
// DDLogLib* logLib = [[DDLogLib alloc] init];
// [logLib printABC];
//app 直接调用
DDLogFileManagerDefault *logFileManager = [[DDLogFileManagerDefault alloc] init];
DDFileLogger* _fileLogger = [[DDFileLogger alloc] initWithLogFileManager:logFileManager];
_fileLogger.rollingFrequency = 60 * 60 * 24; // 24 hour rolling
_fileLogger.logFileManager.maximumNumberOfLogFiles = 7; // a weeks worth
//#ifdef DEBUG
[DDLog addLogger:[DDTTYLogger sharedInstance]];// this is log to xcode window.
//#else
[DDLog addLogger:_fileLogger];
//#endif
DDLogInfo(@"application ABC");
return YES;
}
12、运行正常打印。
iOS在Cocoa Touch Static Library使用CocoaPods的更多相关文章
- ios中静态库的创建和使用、制作通用静态库(Cocoa Touch Static Library)
创建静态库可能出于以下几个理由: 1.你想将工具类代码或者第三方插件快捷的分享给其他人而无需拷贝大量文件.2.你想让一些通用代码处于自己的掌控之下,以便于修复和升级.3.你想将库共享给其他人,但不想让 ...
- 使用Xcode 5创建Cocoa Touch Static Library(静态库)
转自:http://blog.csdn.net/jymn_chen/article/details/21036035 首先科普一下静态库的相关知识: 程序编译一般需经预处理.编译.汇编和链接几个步骤. ...
- iOS制作Static Library(静态库),实现多工程的连编
在iOS开发中,我们会发现一些偏底层或基础代码是直接可以复用的,当我们换一个项目,改变的只需要是偏上层的业务逻辑代码,所以我们可以把这部分基础代码制作为一个静态库static library,并不断扩 ...
- iOS 元件组件-创建静态库static library
概述 在项目开发的过程中,经常使用静态库文件.例如两个公司之间业务交流,不可能把源代码都发送给另一个公司,这时候将私密内容打包成静态库,别人只能调用接口,而不能知道其中实现的细节. 库是一些没有mai ...
- Cocoa Touch事件处理流程--响应者链
Cocoa Touch事件处理流程--响应者链 作者:wangzz 原文地址:http://blog.csdn.net/wzzvictory/article/details/9264335 转载请注明 ...
- Cocoa Touch(一)开发基础:Xcode概念、目录结构、设计模式、代码风格
Xcode相关概念: 概念:project 指一个项目,该项目会负责管理软件产品的全部源代码文件.全部资源文件.相关配置,一个Project可以包含多个Target. 概念:target 一个targ ...
- Swift—Cocoa Touch设计模式-备
目标(Target)与动作(Action)是iOS和OS X应用开发的中事件处理机制. 问题提出 如图所示是一个ButtonLabelSample案例设计原型图,其中包含一个标签和一个按钮,当点击 ...
- UI - Cocoa Touch框架
Cocoa Touch 层 Cocoa Touch层包括创建 iOS应用程序所需的关键框架. 上至实现应用程序可视界面,下至与高级系统服务交互.都须要该层技术提供底层基础.在开发应用程序的时候.请尽可 ...
- iOS 快捷下载和安装并使用CocoaPods
CocoaPods是什么? 当你开发iOS应用时,会经常使用到很多第三方开源类库,比如JSONKit,AFNetWorking等等.可能某个类库又用到其他类库,所以要使用它,手动一个个去下载所需类库十 ...
随机推荐
- jquery升级换代
其实从去年开始1.9以上新版的jquery已不再支持toggle方法和live方法. live用on方法替代. 话说这个方法确实挺方便的,那么怎么交替点击呢,html的checked属性我觉得不是很好 ...
- 【VS调试】C#读写Windows 7注册表时抛出“不允许所请求的注册表访问权”的解决办法
原文:[VS调试]C#读写Windows 7注册表时抛出"不允许所请求的注册表访问权"的解决办法 项目 - 属性 - 安全性,"使用ClickOnce",修改a ...
- 如何使用json在前后台进行数据传输
上一篇博客写到用javascript生成多组文本,可以让数据的输入不受显示,现在我们需要把这些输入写入数据库,这里就用到json传入. 首先,我们来写一下后台如何生成要传输的数据 function g ...
- LVS+Keepalived+Nginx+Tomcat高可用负载均衡集群配置(DR模式,一个VIP,多个端口)
一.概述 LVS作用:实现负载均衡 Keepalived作用:监控集群系统中各个服务节点的状态,HA cluster. 配置LVS有两种方式: 1. 通过ipvsadm命令行方式配置 2. 通过Red ...
- iTerm2 + oh my zsh代替mac自带的bash shell
使用Solarized dark配色方案 需要字体menlo for powerline oh-my-zsh主题使用agnoster,这个主题默认的路径是全路径,当路径很长的时候,就会占很长的空间,可 ...
- log4cxx在vs2013的静态编译
网络上找了一圈,结果都是通过修改代码来编译,做为强迫症患者接受不了这种修改代码却无法预知代码带来影响的方式,而且没有静态编译的方法,为了方便其他人后续不在走弯路,提供自己的编译方法. 虽然最终的目的是 ...
- iOS开发ARC入门和使用
本文引自:http://www.onevcat.com/2012/06/arc-hand-by-hand/ 英文原版:http://www.raywenderlich.com/5677/beginni ...
- NOI题库2454 雷涛的小猫
2454:雷涛的小猫 总时间限制: 20000ms 单个测试点时间限制: 10000ms 内存限制: 65536kB 描述 雷涛同学非常的有爱心,在他的宿舍里,养着一只因为受伤被救助的小猫(当然,这样 ...
- 最小生成树 10.1.5.253 1505 poj 1258 http://poj.org/problem?id=1258
#include <iostream>// poj 1258 10.1.5.253 1505 using namespace std; #define N 105 // 顶点的最大个数 ( ...
- 什么是左值(what is a lvalue)?
引用并翻译自<C++ premier plus> 左值是可以通过地址引用的数据对象(data object),例如,变量,数组的元素,结构体的成员,引用变量,以及复引用的指针(defere ...