Swift: How to install SwiftyJson using cocoapods?

家住魔仙堡 提交于 2020-01-07 08:57:12

问题


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'

My 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

After adding that I ran pod install succesfully:

[~/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'

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.


回答1:


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

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


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.



来源:https://stackoverflow.com/questions/33321138/swift-how-to-install-swiftyjson-using-cocoapods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!