Xcode6 creates a framework (using a third-party dependency framework) and xcode6framework

Source: Internet
Author: User

Xcode6 creates a framework (using a third-party dependency framework) and xcode6framework

In the past two days, the framework has been used for research, and I have used xcode6.1 and AFNetworing.

Reprinted please indicate http://blog.csdn.net/mengxiangyue

Below are the steps:

1. Create a single view application project and Open Main. storyboard, select the only ViewController, and click Editor-> embed in-> navigation Controller in the menu bar (embedded in this navigation controller is only required for testing and not required ).

2. Click the project and click the plus sign in the lower-left corner of the targets project. For example, TTTTTTT in the project is the Framework I have added ):

The following figure is displayed. Select Cocoa Touch Framework.


After selecting next, enter the name of the corresponding framework. The framework project is created here.

3. Introduce AFNetWorking and drag AFNetWorking to the project. The following figure is displayed. Finish the import.

4. Create classes in the Framework

Right-click the created Framework and choose new File --> Coco Touch Class to create an Objective-C Class XYTestViewController. The Class content is as follows: (this Class is just a simple demonstration, AFnetworking is referenced in it)

#import <UIKit/UIKit.h>#import "AFNetworking.h"@interface XYTestViewController : UIViewController@end
. M file

# Import "XYTestViewController. h "@ interface XYTestViewController () @ end @ implementation XYTestViewController-(void) viewDidLoad {[super viewDidLoad]; NSLog (@" "); self. view. backgroundColor = [UIColor whiteColor]; UIButton * button = [[UIButton alloc] initWithFrame: CGRectMake (100,100,200, 60)]; [button setTitle: @ "click" forState: UIControlStateNormal]; [button setTitleColor: [UIColor blackColor] forState: UIControlStateNormal]; [button addTarget: self action: @ selector (click :) forControlEvents: UIControlEventTouchUpInside]; [self. view addSubview: button];}-(void) click :( UIButton *) sender {NSLog (@ "click"); AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager manager]; manager. responseSerializer = [AFHTTPResponseSerializer serializer]; AFHTTPRequestOperation * option1 = [manager GET: @ "http://www.baidu.com" parameters: nil success: ^ (AFHTTPRequestOperation * operation, id responseObject) {NSLog (@ "xxxxxxxxxxxx ---- % @", responseObject);} failure: ^ (AFHTTPRequestOperation * operation, NSError * error) {}];}-(void) didReceiveMemoryWarning {[super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated .} /* # pragma mark-Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation-(void) prepareForSegue :( UIStoryboardSegue *) segue sender :( id) sender {// Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller .} * // @ end

5 Test

Modify the ViewController class in the project. The modified content is as follows:

. H file

#import <UIKit/UIKit.h>#import "XYTestViewController.h"@interface ViewController : UIViewController@end
. M file

//// ViewController. m // sssssssssssss // Created by mxy on 14-11-11. // Copyright (c) 2014 mxy. all rights reserved. // # import "ViewController. h "@ interface ViewController () @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; UIButton * button = [[UIButton alloc] initWithFrame: CGRectMake (100,100,200, 60)]; [button setTitle: @ "go to the next VC" forState: UIControlStateNormal]; [button setTitleColor: [UIColor blackColor] forState: UIControlStateNormal]; [button addTarget: self action: @ selector (click :) forControlEvents: UIControlEventTouchUpInside]; [self. view addSubview: button];}-(void) click :( UIButton *) sender {NSLog (@ "go to the next VC"); XYTestViewController * testVC = [[XYTestViewController alloc] init]; [self. navigationController pushViewController: testVC animated: YES];}-(void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} @ end

Click "run" to see if it works normally. If it works properly, it will be okay, and then proceed to the next step.

6. Generate the framework

During the running process, we have actually generated the framework. Click products In the project to view the generated framework. Right-click show In Finder to view the generated framework. There are four folders in the parent directory: Debug-iphoneos, Debug-iphonesimulator, Release-iphoneos, and Release-iphonesimulator, which correspond to the frameworks used in different situations.

The options 1 and 2 in the following figure are different, and the frameworks compiled by commond + B are different:

1 framework 2 iPhone simulator scheme debug will compile Debug-iphonesimulator

1 framework 2 IOS Device scheme debug will compile Debug-iphoneos

1 framework 2 the iPhone simulator scheme Release will compile the Release-iphonesimulator

1 framework 2 IOS Device scheme Release will compile Release-iphoneos


Set open APIs, for example:

7. Use

Create a new project, import the appropriate framework to the project, and write the code for use. Because the framework uses AFNetworking but does not package it into the Framework, therefore, you need to manually import a framework for the newly created Project. If the following error occurs in the Code:

Dyld: Library not loaded: @ rpath/TTTTTTTT. framework/TTTTTTTT
Referenced from:/Users/mxy/Library/Developer/CoreSimulator/Devices/72AF601F-3B90-4720-ACB0-E98EE7FD26FE/data/Containers/Bundle/Application/logs/testFFFFFF. app
Reason: image not found

I personally understand the above error because the framework we wrote was not found during the project compilation process.

Search for runpath search paths in buildsetting of the project, add $ (SRCROOT), and run normally.


Finally, I have finished writing. Welcome to make a picture.


Related Article

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.