我可以从照片库中选择并显示图像,但我的目标是能够将选择的图像或文件路径保存到核心数据,以便在选择保存的记录时也会显示图像.
我有CoreData工作,我能够从CoreData显示文本很好,它只是图像阻止我.
@IBAction func addPic(sender: AnyObject) {
pickerController.delegate = self
pickerController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
// 2
self.presentViewController(pickerController, animated: true, completion: nil)
// Displays image
func imagePickerController(picker: UIImagePickerController!,didFinishPickingMediaWithInfo info: NSDictionary!){
image.image = info[UIImagePickerControllerOriginalImage] as? UIImage
self.dismissViewControllerAnimated(true, completion: nil)
Run Code Online (Sandbox Code Playgroud) 我试图循环附加的JSON并打印出数据中每个项目的名称和价格.我的问题是它重复打印出的名字和价格不超过50次.我错过了什么?什么会让我让它显示下一个项目?这只是一个基于代码的示例数据.
我的守则
import json
import requests
request = requests.get('http://example.com/json')
for item in request:
data = request.json()
data = data['items'][0]
price = data['salePrice']
name = data['name']
print name
Run Code Online (Sandbox Code Playgroud)
数据
{"items":[ {
"itemId" : 5969538,
"parentItemId" : 5969538,
"name" : "Breakfast Nook 3 Piece Corner Dining Set, Black",
"salePrice" : 288.99,
"shortDescription" : "Create extra space and a cozy area to dine and relax with this stylish nook corner dining set. A rich black finish adds sophistication to any dining area, while …Run Code Online (Sandbox Code Playgroud)