使用TFHpple框架从Swift编译错误 [英] Compilation error using TFHpple framework from Swift

查看:233
本文介绍了使用TFHpple框架从Swift编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个HTML,

 < div class =header1style =text-align:center; > 


< div class =s>
< center>
< table>
< tr>
< td>
< ul style =position:relative;>
< li>
< a>
< p>
Apple Kid

< / p>

,我想使用Swift输出Apple kid >

我使用TFHpple框架为此,但在添加所有必要的东西,它显示一个错误。类似于Objective-C文件

  XPathQuery.h 
//
// XPathQuery.h
// FuelFinder
//
//由Matt Gallagher于4/08/08创建。
//版权所有2008 __MyCompanyName__。版权所有。
//

NSArray * PerformHTMLXPathQuery(NSData * document,NSString * query);
NSArray * PerformHTMLXPathQueryWithEncoding(NSData * document,NSString * query,NSString * encoding);
NSArray * PerformXMLXPathQuery(NSData * document,NSString * query);
NSArray * PerformXMLXPathQueryWithEncoding(NSData * document,NSString * query,NSString * encoding);

这些函数显示关于未知类型的错误。



XpathQuery.m

  // 
// XPathQuery.m
FuelFinder
//
//由Matt Gallagher于4/08/08创建。
//版权所有2008 __MyCompanyName__。版权所有。
//

#importXPathQuery.h

#import< libxml / tree.h>
#import< libxml / parser.h>
#import< libxml / HTMLparser.h>
#import< libxml / xpath.h>
#import< libxml / xpathInternals.h>

NSDictionary * DictionaryForNode(xmlNodePtr currentNode,NSMutableDictionary * parentResult,BOOL parentContent);
NSArray * PerformXPathQuery(xmlDocPtr doc,NSString * query);


解决方案

您应该分享您收到的确切错误,使用TFHpple从Swift没有问题。与Objective-C一样,您必须


  • 确保您链接到 libxml

  • add $(SDKROOT)/ usr / include / libxml2 到创建设置中的标题搜索路径




请参阅Wenderlich的如何在iOS上解析HTML 或Cocoa with Love的在Cocoa中使用libxml2进行XML解析和XPath查询



当您将TFHpple源添加到项目时,应该提示您创建一个桥接头。这样做,然后添加 #importTFHpple到它。有关详情,请参阅将Objective-C导入Swift 部分.html#// apple_ref / doc / uid / TP40014216-CH10-XID_77rel =nofollow> Swift和Objective-C in the Same Project chapter in the Using Swift with Cocoa and Objective-C



一旦你这样做,你应该能够使用TFHpple没有来自Swift的事件。


I have this HTML,

 <div class="header1" style="text-align: center;">


 <div class="s">
          <center>
                  <table>
       <tr>
                          <td>
                     <ul style="position: relative;">
                       <li>
                    <a>
         <p>
   Apple Kid

        </p>

and I want to get the the word "Apple kid" as an output using Swift.

I used the TFHpple Framework for this, but after adding all the necessary things it showing an error. Like in the Objective-C file

the  XPathQuery.h
//
//  XPathQuery.h
//  FuelFinder
//
//  Created by Matt Gallagher on 4/08/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

NSArray *PerformHTMLXPathQuery(NSData *document, NSString *query);
NSArray *PerformHTMLXPathQueryWithEncoding(NSData *document, NSString *query,NSString *encoding);
NSArray *PerformXMLXPathQuery(NSData *document, NSString *query);
NSArray *PerformXMLXPathQueryWithEncoding(NSData *document, NSString *query,NSString *encoding);

It showing an error at these functions about Unknown type.

The XpathQuery.m

//
//  XPathQuery.m
//  FuelFinder
//
//  Created by Matt Gallagher on 4/08/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "XPathQuery.h"

#import <libxml/tree.h>
#import <libxml/parser.h>
#import <libxml/HTMLparser.h>
#import <libxml/xpath.h>
#import <libxml/xpathInternals.h>

NSDictionary *DictionaryForNode(xmlNodePtr currentNode, NSMutableDictionary *parentResult,BOOL parentContent);
NSArray *PerformXPathQuery(xmlDocPtr doc, NSString *query);

解决方案

You should share the precise errors you received, but I had no problems using TFHpple from Swift. As you do with Objective-C, you have to

  • make sure you link to the libxml library in your build phases

  • add $(SDKROOT)/usr/include/libxml2 to your header search paths in the build settings

See the installation instructions on Wenderlich's How To Parse HTML on iOS or Cocoa with Love's Using libxml2 for XML parsing and XPath queries in Cocoa.

When you add the TFHpple source to your project, you should be prompted to create a bridging header. Do so, and then add #import "TFHpple" to it. For more information, see the Importing Objective-C into Swift section of the Swift and Objective-C in the Same Project chapter of the Using Swift with Cocoa and Objective-C guide.

Once you do that, you should be able to use TFHpple without incident from Swift.

这篇关于使用TFHpple框架从Swift编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆