我收到一个JSON,我想解析它以获得一个值.我这样做
let ddd = oneJson["restaurantId"] as! Int
print("ddd = \(ddd)")
let restaurantId = oneJson["restaurantId"] as! Int64
Run Code Online (Sandbox Code Playgroud)
如你所见,我正在解析相同的字段.这是我的JSON
"location":"location here location","restaurantId":0
Run Code Online (Sandbox Code Playgroud)
print语句工作正常,但我得到了一个例外 oneJson["restaurantId"] as! Int64
我怎么能UIImage在20秒内(屏幕每秒约35个像素)从屏幕底部移动到屏幕顶部我并不是说你应该自己拖动它,但它应该自动移动到顶部.谢谢
我目前有这个设置,我很乐意在计算距离时从Km改为Miles.这是我目前的代码:
CLLocation *userloc = [[CLLocation alloc] initWithLatitude:locationManager.location.coordinate.latitude longitude:locationManager.location.coordinate.longitude];
CLLocation *loc = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
CLLocationDistance distance2 = [userloc distanceFromLocation:loc]/ 1000;
NSLog(@"%f",distance2);
[distance setText:[NSString stringWithFormat:@"%.2f km", distance2]];
}
Run Code Online (Sandbox Code Playgroud) 我正在ProgressViewSwift 工作
这是我的代码
var request = HTTPTask()
let downloadTask = request.download(urlm!, parameters: nil, progress: {(complete: Double) in
println("percent complete: \(Float(complete))")
self.Progress.setProgress(Float(complete), animated: true)
Run Code Online (Sandbox Code Playgroud)
尽管complete给出了这个输出
percent complete: 0.00480848
percent complete: 0.0089619
percent complete: 0.0132512
percent complete: 0.0175405
percent complete: 0.0221036
percent complete: 0.0264841
percent complete: 0.0308647
percent complete: 0.0350627
percent complete: 0.0392608
percent complete: 0.0434588
percent complete: 0.0513073
percent complete: 0.0555054
percent complete: 0.0598859
percent complete: 0.0642665
percent complete: 0.0688296
percent complete: 0.0731189
percent complete: 0.0774994
percent …Run Code Online (Sandbox Code Playgroud) 我想在特定情况下捕获图像,例如按下按钮时; 但我不想显示任何视频预览屏幕.我想captureStillImageAsynchronouslyFromConnection是我需要用于此场景的东西.目前,如果我显示视频预览,我可以捕获图像.但是,如果我删除代码以显示预览,应用程序将崩溃并显示以下输出:
2012-04-07 11:25:54.898 imCapWOPreview [748:707]***由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:'*** - [AVCaptureStillImageOutput captureStillImageAsynchronouslyFromConnection:completionHandler:] - 传递了非活动/无效连接. "***第一掷调用堆栈:(0x336ee8bf 0x301e21e5 0x3697c35d 0x34187 0x33648435 0x310949eb 0x310949a7 0x31094985 0x310946f5 0x3109502d 0x3109350f 0x31092f01 0x310794ed 0x31078d2d 0x37db7df3 0x336c2553 0x336c24f5 0x336c1343 0x336444dd 0x336443a5 0x37db6fcd 0x310a7743 0x33887 0x3382c)终止叫做抛出异常(LLDB)
所以这是我的实现:
BIDViewController.h:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface BIDViewController : UIViewController
{
AVCaptureStillImageOutput *stillImageOutput;
}
@property (strong, nonatomic) IBOutlet UIView *videoPreview;
- (IBAction)doCap:(id)sender;
@end
Run Code Online (Sandbox Code Playgroud)
BIDViewController.m中的相关人员:
#import "BIDViewController.h"
@interface BIDViewController ()
@end
@implementation BIDViewController
@synthesize capturedIm;
@synthesize videoPreview;
- (void)viewDidLoad
{
[super viewDidLoad];
[self setupAVCapture];
}
- …Run Code Online (Sandbox Code Playgroud) 我正在制作bukkit插件并返回一个函数List<Map<?, ?>>,如果我这样做:
List<Map<String, String>> circle = FileManager.area.getMapList("circles");
Run Code Online (Sandbox Code Playgroud)
我收到无法转换的错误.怎么办?
错误:
List<Map<?, ?>> cannot be converted into List<Map<String, String>>
Run Code Online (Sandbox Code Playgroud) 我NSAttributedString在内容中使用表情符号的结尾没有被格式化.我正在尝试格式化整个字符串(在此示例中将文本颜色设置为白色,以简化),但是当放入文本时,某些文本保持未格式化UILabel.

目前,我正在使用
let attributedString = NSMutableAttributedString(string: contents)
attributedString.addAttribute(
NSForegroundColorAttributeName,
value: UIColor.white,
range: NSMakeRange(0, contents.characters.count)
)
label.attributedText = attributedString
Run Code Online (Sandbox Code Playgroud)
我也试过通过使用contents.utf8.count获得长度,但获得相同的结果.
我注意到未格式化的字符数与字符串中的表情符号数相同.这可能与正在发生的事情有关吗?
nsattributedstring uilabel ios nsmutableattributedstring swift
我正在尝试像摄像机视图一样做一个像摄像机视图,相机流填充所有屏幕.
这是代码:
func beginSession() {
var err : NSError? = nil
// try to open the device
let videoCapture = AVCaptureDeviceInput(device: captureDevice, error: &err)
if err != nil {
// Fail silently. Do better in the real world.
println("Capture session could not start: \(err?.description)")
return
}
// add video input
if captureSession.canAddInput(videoCapture) {
captureSession.addInput(videoCapture)
}
// config capture session
if !captureSession.running {
// set JPEG output
stillImageOutput = AVCaptureStillImageOutput()
let outputSettings = [ AVVideoCodecKey : AVVideoCodecJPEG ]
stillImageOutput!.outputSettings = outputSettings …Run Code Online (Sandbox Code Playgroud) 这是我目前的代码
class HelloWorld {
func foobar() {
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
当调用它和意外发生时,如何使此函数抛出异常?
将来,C 风格的 for 语句将从 Swift 中删除。虽然有许多替代方法可以使用 C 风格的 for 语句,例如 usingstride或..<运算符,但这些仅适用于某些条件
例如,在旧版本的 swift 中,可以String.CharacterView.Index使用 C 样式的 for 语句循环遍历字符串的每个其他索引 ,
for var index = string.startIndex; index < string.endIndex; index = string.successor().successor(){
//code
}
Run Code Online (Sandbox Code Playgroud)
然而,这现在已被弃用。有一种方法可以做同样的事情,使用while循环
var index = string.startIndex
while index < string.endIndex{
//code
index = index.successor().successor()
}
Run Code Online (Sandbox Code Playgroud)
但这只不过是一种解决方法。有..<运算符,它非常适合循环遍历字符串的每个索引
for index in string.startIndex..<string.endIndex
Run Code Online (Sandbox Code Playgroud)
然而,这无助于循环遍历字符串的每个其他索引或字符串的每个第 n 个索引
除了循环之外,还有更多“快速”的方式来循环遍历字符串的所有其他索引while吗?这个问题不仅与字符串索引有关,而且只与具有.successor()一般功能的对象有关,例如wherestride和..<don't work。