我正在尝试在两个整数之间生成随机值.我试过这个,从0开始,
let randomNumber = arc4random_uniform(10)
println(randomNumber)
Run Code Online (Sandbox Code Playgroud)
但我需要10到50之间的值.
Xcode 5.0.2当我在Simulator中运行我的应用程序时,我已经安装了大部分时间.
我收到错误,这是 -


如果有人可以告诉我,Cause of Error和How it can be resolved.
我试图在特定的持续时间内动画图像.它在Objective C中运行正常.但是,它不适用于Swift,我的错误在哪里?
Objective-C的代码是 -
-(void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *imgListArray=[NSMutableArray array];
for (int i=0; i<=11; i++)
{
NSString *strImageName=[NSString stringWithFormat:@"c%d.png", i];
NSLog(@"%@",strImageName);
UIImage *image=[UIImage imageNamed:strImageName];
[imgListArray addObject:image];
}
self.imgView.animationImages = imgListArray;
self.imgView.animationDuration =1.0f;
[self.imgView startAnimating];
// Do any additional setup after loading the view, typically from a nib
}
Run Code Online (Sandbox Code Playgroud)
迅捷守则是 -
override func viewDidLoad()
{
super.viewDidLoad()
var imgListArray :NSMutableArray = []
for countValue in 1...11
{
var strImageName : String = "c\(countValue).png"
var image = UIImage(named:strImageName) // suggested by Anil …Run Code Online (Sandbox Code Playgroud) 我正在使用iOS应用程序,我使用谷歌驱动器访问我的文件,登录和列表文件工作正常,但我只是问我如何在登录界面上添加取消按钮由谷歌驱动器sdk提供查看图像怒吼

因为,你看到没有办法做一个cancel或一个go back按钮.
这是我的代码
// verify if the user is already connected or not
- (void)checkIfIsConnected
{
// Check for authorization.
GTMOAuth2Authentication *auth =
[GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName
clientID:kClientID
clientSecret:kClientSecret];
if ([auth canAuthorize]) {
[self isAuthorizedWithAuthentication:auth];
}else
{
[self ConnectToDrive];
}
}
- (GTLServiceDrive *)driveService {
static GTLServiceDrive *service = nil;
if (!service) {
service = [[GTLServiceDrive alloc] init];
// Have the service object set tickets to fetch consecutive pages
// of the feed so we do not …Run Code Online (Sandbox Code Playgroud) 嗨,我崩溃了,
当我试图在背景中向数据库插入1000条记录时,我得到以下异常:
CoreData: error: Serious application error.在Core Data更改处理期间捕获到异常.
这通常是观察者中的一个错误
NSManagedObjectContextObjectsDidChangeNotification. -[__NSCFSet addObject:]: attempt to insert nil with userInfo (null)2013-11-19 09:41:19.587 3pTalk[7487:907]
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFSet addObject:]: attempt to insert nil'
Run Code Online (Sandbox Code Playgroud)
我用代码插入了objexts
dispatch_queue_t myBackgroundQ = dispatch_queue_create("com.sample.addressbook", NULL);
// Could also get a global queue; in this case, don't release it below.
dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC);
dispatch_after(delay, myBackgroundQ, ^(void){
[self userAddressbook];
});
dispatch_release(myBackgroundQ);
[self performSelectorOnMainThread:@selector(startSyncLoader) withObject:nil waitUntilDone:YES];
Run Code Online (Sandbox Code Playgroud) 我用这种方式解析了以下RSS(http://timesofindia.indiatimes.com/rss.cms) -
我的代码 -
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>News Parser</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<link rel="stylesheet" href="css/jquery.mobile-1.4.2.min.css" />
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/jquery.mobile-1.4.2.min.js"></script>
<script type="text/javascript">
var url1 = "https://www.readability.com/api/content/v1/parser?url=";
var testurl = "http://timesofindia.indiatimes.com/rss.cms";
var urltoken = "&token=18ba7d424a0d65facdaea8defa356bc3e430f8ce";
var finalurl = url1 + testurl + urltoken;
console.debug(finalurl)
$(function()
{
$.ajax(
{
url:finalurl,
dataType: "json",
contentType:"application/json",
success: function (data)
{
console.log(data);
console.log(data.content);
//console.error(JSON.parse(data.content));
$("body").empty().append(data.content);
},
error:function(d)
{
console.log(d);
}
});
});
</script>
<style type="text/css">
p
{
color: green;
} …Run Code Online (Sandbox Code Playgroud) 我正试图在一个按钮上显示一个图像,我正在通过按钮获得图像的蓝色打印,我到目前为止已尝试过 -
override func viewDidLoad()
{
super.viewDidLoad()
var birdTexture1 = UIImage(named: "fish.png") as UIImage
button1.frame = CGRectMake(100, 10, 50, 150)
button1.setImage(birdTexture1, forState: .Normal)
button1.setTitle("Testing", forState: UIControlState.Normal)
button1.addTarget(self, action: "btnAction:", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(button1)
// Do any additional setup after loading the view, typically from a nib.
}
Run Code Online (Sandbox Code Playgroud)
通过上面的代码,我得到了以下输出

但实际图像是这样的 -

在我的应用程序中,我们保留了通过gmail登录的选项.我要求检索Gmail联系人.
在下面的方法中,我使用AUTH对象(一旦成功)通过创建具有URL请求抓取Gmail联系人:" https://www.google.com/m8/feeds/contacts/default/full "
- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error {
if(!error) {
auth.clientID =myClientId;
auth.clientSecret =myClientSecret;
auth.scope= @"https://www.googleapis.com/auth/contacts.readonly";
NSString *urlStr = @"https://www.google.com/m8/feeds/contacts/default/full";
NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"GET"];
[request setValue:@"3.0" forHTTPHeaderField:@"GData-Version"];
[auth authorizeRequest:request
completionHandler:^(NSError *error) {
NSString *output = nil;
if (error) {
output = [error description];
} else {
NSURLResponse *response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
if (data) {
// API fetch succeeded :Here I am getti
output = …Run Code Online (Sandbox Code Playgroud) 我正在使用适用于iOS的Google Map SDK.我在驾驶模式下绘制折线.
但是当我停下来,然后缩放谷歌地图时,我的当前位置光标会自动移动并重绘之字形折线,因为所有先前绘制的折线都会重叠并且折线会完全改变.当我进入背景和驱动时会发生事情.
我能知道为什么会这样吗?如何在同一路径中同时在驾驶和步行模式下绘制平滑折线.
我的守则 -
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
pointString=[NSString stringWithFormat:@"%f,%f",newLocation.coordinate.latitude,newLocation.coordinate.longitude];
CLLocationDistance kilometers = [newLocation distanceFromLocation:oldLocation] / 1000;
NSLog(@"Distance Travelled in Kilometer :%f",kilometers);
[self.points addObject:pointString];
GMSMutablePath *path = [GMSMutablePath path];
for (int i=0; i<self.points.count; i++)
{
NSArray *latlongArray = [[self.points objectAtIndex:i]componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]];
[path addLatitude:[[latlongArray objectAtIndex:0] doubleValue] longitude:[[latlongArray objectAtIndex:1] doubleValue]];
}
if (self.points.count>2)
{
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
polyline.strokeColor = [UIColor blueColor];
polyline.strokeWidth = 5.f;
polyline.map = mapView_;
self.mapContainerView = mapView_;
}
}
Run Code Online (Sandbox Code Playgroud)
如果,我保持在相同的位置,那么Googme …
我正在尝试使用UITouch将按钮从一个位置拖动到另一个位置.但是我无法拖动它.我在添加按钮目标时遇到问题...
我的代码 -
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let btn_swap = UIButton.buttonWithType(UIButtonType.Custom) as UIButton!
btn_swap .setTitle("Drag Me", forState: UIControlState.Normal)
btn_swap.backgroundColor = UIColor.yellowColor()
btn_swap.addTarget(self, action: "wasDragged:", forControlEvents: UIControlEvents.TouchDragInside)
btn_swap.frame = CGRectMake((self.view.bounds.size.width - 100)/2.0,
(self.view.bounds.size.height - 50)/2.0,
100, 50)
self.view.addSubview(btn_swap)
self.creation_of_btn()
}
func wasDragged (buttn : UIButton, event :UIEvent)
{
var touch : UITouch = event.touchesForView(buttn) . anyObject() as UITouch
var previousLocation : CGPoint = touch .previousLocationInView(buttn)
var location …Run Code Online (Sandbox Code Playgroud) ios ×4
swift ×4
objective-c ×3
cordova ×1
core-data ×1
google-api ×1
google-oauth ×1
google-plus ×1
ios5 ×1
ios7 ×1
ipad ×1
javascript ×1
random ×1
xcode5 ×1