Swift:如何使用cocoapods安装SwiftyJson? [英] Swift: How to install SwiftyJson using cocoapods?

查看:328
本文介绍了Swift:如何使用cocoapods安装SwiftyJson?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在此处安装cocoapods: https://github.com/SwiftyJSON/SwiftyJSON 但是当我在视图文件中导入SwiftyJSON 时,它说没有这样的模块'SwiftyJSON'

I'm trying to install cocoapods here: https://github.com/SwiftyJSON/SwiftyJSON but when I import SwiftyJSON in my view file, it says No such module 'SwiftyJSON'

我的Podfile:

platform :ios, '8.0'
inhibit_all_warnings!
use_frameworks!

target 'SherpaNewYork' do
  pod 'GoogleMaps'
  pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git'
end

之后添加我成功运行 pod安装

[~/Documents/ios/Sherpa]$ pod install                                                                                                                                              ✭ git:master ruby:2.2.2
Updating local specs repositories
Analyzing dependencies
Pre-downloading: `SwiftyJSON` from `https://github.com/SwiftyJSON/SwiftyJSON.git`
Downloading dependencies
Using GoogleMaps (1.10.4)
Installing SwiftyJSON (2.3.0)
[!] Pods written in Swift can only be integrated as frameworks; add `use_frameworks!` to your Podfile or target to opt into using it. The Swift Pod being used is: SwiftyJSON
[~/Documents/ios/Sherpa]$ pod install                                                                                                                                              ✭ git:master ruby:2.2.2
Updating local specs repositories
Analyzing dependencies
Pre-downloading: `SwiftyJSON` from `https://github.com/SwiftyJSON/SwiftyJSON.git`
Downloading dependencies
Using GoogleMaps (1.10.4)
Installing SwiftyJSON (2.3.0)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.

当我不导入时,它给我错误:

When I don't import it it gives me errors:

let jsonResponse: [Dictionary<String, AnyObject>] = [
  ["id": "1",
    "name": "Crumbs Bakery",
    "icon_image": "food_icon_small",
    "latitude": 40.714,
    "longitude": -74.000
  ],
  ["id": "2",
    "name": "Shake Shack",
    "icon_image": "food_icon_small",
    "latitude": 40.715,
    "longitude": -74.001
  ]
]

let data = NSJSONSerialization.dataWithJSONObject(jsonResponse, options: nil, error: nil

JSON(data) // Use of unresolved identifier 'JSON'

我什至关闭了我的Xcode并打开了 AppName.xcworkspace,但没有任何效果我错过了一步吗?我正在使用pod v。0.39.0,部署目标是8.0。

I even closed my Xcode and opened up "AppName.xcworkspace" but nothing works. Am I missing a step? I'm using pod v. 0.39.0 and my deployment target is 8.0.

推荐答案

编辑:误解了您的问题。如果您使用Cocoapods进行安装,则仍然需要 impo rt SwiftyJSON

Edit: Misread your question. If you install it using Cocoapods, you still need to import SwiftyJSON.

尝试 Product->清洁,然后清洁产品->生成。也许可以解决问题。

Try Product -> Clean then Product -> Build. That may solves the problem.

您不需要导入它。只需使用它。您只需要 import 即可获得单独的模块 Swift访问控制,不适用于源文件

You don't need to import it. Just use it. You only need import for a separated module: Swift Access Controll, not for source file.

这篇关于Swift:如何使用cocoapods安装SwiftyJson?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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