iOS in Cocoa Touch Static library using Cocoapods

Source: Internet
Author: User

1. Create a new static library project in Xcode: Ddloglib.

2, add the external exposed interface header file DDLogLibHeader.h

3, the command line into the Ddloglib directory, run pod init, and modify the Podfile

4. Run pod install and open ddloglib.xcworkspace.

5. Run Pod spec create ddloglib, creating Ddloglib.podspec file, and edit.

# 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 on 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'll help people to find your library, and whilst it

# can feel like a chore into fill in it's definitely to your advantage. The

# Summary should is 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 does?

* CocoaPods'll be using the 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'll detect a license file if there is a named license*

# Popular ones is ' 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 is extracted from the SCM log. e.g. $ git log. CocoaPods Also

# accepts just a name if you ' d rather isn't provide an email address.

#

# Specify a social_media_url where others can refer to, for example a Twitter

# profile URL.

#

S.author = {"hu5675" = "[email protected]"}

# Or Just:s.author = "hu5675"

# s.authors = {"hu5675" = "[email protected]"}

# 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 is retrieved.

# Supports git, Hg, BZR, SVN and HTTP.

#

S.source = {: git = "http://EXAMPLE/DDLogLib.git": Tag = "0.0.1"}

#―――source code――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――#

#

# CocoaPods is smart on how it includes source code. For source files

# giving a folder would include any Swift, H, M, MM, C & CPP files.

# for header files it would include any header in the folder.

# not including the public_header_files would 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 is copied into the

# target Bundle with a build phase script. Anything else would be cleaned.

# 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 can set them in the Xcconfig hash

# where they would only apply to your library. If you depend on other podspecs

# 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, the new project Ddloglibapp, and Ddloglib keep in the same directory, command line into Ddloglibapp, run Pod init, and edit.

# Uncomment this line to define a global platform for your project

# Platform:ios, ' 6.0 '

Target ' Ddloglibapp ' do

Pod ' ddloglib ',:p ath = '. /ddloglib '

End

Target ' ddloglibapptests ' do

End

Target ' ddloglibappuitests ' do

End

7. Run pod install and open Ddloglibapp.xcworkspace compile.

8, implement Printabc method in Ddloglib.

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; 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, called in 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, run Ddloglibapp, all normal.

11, the direct use of ddlog in Ddloglibapp.

#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 is called through a static library

ddloglib* loglib = [[Ddloglib alloc] init];

[Loglib PRINTABC];

App calls directly

Ddlogfilemanagerdefault *logfilemanager = [[Ddlogfilemanagerdefault alloc] init];

ddfilelogger* _filelogger = [[Ddfilelogger alloc] initwithlogfilemanager:logfilemanager];

_filelogger.rollingfrequency = 60 * 60 * 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, run normal printing.

iOS in Cocoa Touch Static library using Cocoapods

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.