小编Jua*_*ero的帖子

在Swift中使用NSNumber numberWithBool

我提交了我的应用程序第2版以供审核,但由于对iCloud的高备份而被拒绝-当时我不知道这一点,因为我只需要在应用程序中拍照即可。现在我尝试转换该代码

NSError *error = nil;
    NSURL *databaseUrl = [NSURL fileURLWithPath:databasePath];
    BOOL success = [databaseUrl setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
    if(!success){
    NSLog(@"Error excluding %@ from backup %@", [databaseUrl lastPathComponent], error);
    }
Run Code Online (Sandbox Code Playgroud)

很快我就无法工作...这就是我到目前为止...

func excludeFromBackup() {
    var error:NSError?
    var fileToExclude = NSURL.fileURLWithPath("path")
    var success:Bool = fileToExclude?.setResourceValue(NSNumber.numberWithBool(true), forKey: NSURLIsExcludedFromBackupKey, error: &error)
    if success {
        println("worked")
    } else {
        println("didn't work")
    }
}
Run Code Online (Sandbox Code Playgroud)

如您所见,我的numberWithBool值失败。

谁能帮我?有人转换过吗?

提前致谢...

nsurl nsnumber ios swift ios8

3
推荐指数
1
解决办法
5704
查看次数

Objective-C中的%d格式说明符

好吧,我有以下代码:

{
    int alfa = CC_RADIANS_TO_DEGREES(atan2(normalized.y, -normalized.x)) + 180;
    NSString * counting = [NSString stringWithFormat:@"fdfg%d.png", alfa];
}
Run Code Online (Sandbox Code Playgroud)

int alfa0和之间带来一个数字360.

我想要实现的是counting字符串值等于图像文件,我有360个图像文件,都具有这种格式"fdfg0000.png" "fdfg0024.png" "fdfg0360.png",从0增加到360,依此类推......

%d运营商不读书的价值,因为所有领先的文件名中的零已经由创建它们的程序输出,没有机会对其进行修改,我已经手动360个文件重命名为这样的格式:"fdfg1.png" "fdfg24.png" "fdfg340.png"和多数民众赞成在格式% d正确读取.

所以我的问题是,无论如何要读取原始文件在运算符函数中包含的所有四个零?

或者有没有人知道自动重命名360文件的方法?

objective-c string-formatting

2
推荐指数
1
解决办法
5346
查看次数

修改另一个视图控制器swift中的一个变量

我正在Swift中开发一个应用程序,它在一个主旨中告诉人们各种货币的比特币价格.要选择货币,用户可以从具有UITableView的视图控制器中的列表中进行选择.这是currencyViewController,它是从我的主屏幕viewController呈现的.

我想要发生的是,当用户解雇currencyViewController时,它会将一个字符串传递给主viewController中的UIButton.

这是应该传递数据的prepareForSegue函数:

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    if (segue.identifier == "presentCurrency") {

        currencySelector.setTitle("\currencySelected", forState: UIControlState.Normal)

    }
}
Run Code Online (Sandbox Code Playgroud)

CurrencySelector是主viewController中的UIButton,而currencySelected是第二个视图控制器currencyViewController中的变量.

它给出错误"文字中无效的转义序列"

所以,我把它缩小到两个问题之一:

  1. 来自viewController的变量无法从currencyViewController中"看到".如果是这样,我如何从CurrencyViewController修改CurrencySelector的文本?

  2. 出于某种原因,当用户退出推送的CurrencyViewControler时,不会调用prepareForSegue.

这里发生了什么?谢谢,道歉 - 我只是一个快速的新手.

pushviewcontroller ios swift

2
推荐指数
1
解决办法
6487
查看次数

在Swift中的UITextView中检测空行和缺少文本

我以编程方式创建了一个UITextView,并添加了一个占位符,如下所示:

    //textView
    textView.frame = CGRectMake(viewSize.width * 0.05, contentView.frame.height - viewSize.width * 0.05, viewSize.width - viewSize.width * 0.05 * 2, -viewSize.height * 0.220833)
    self.textView.delegate = self
    self.textView.text = "Agregue una descripción..."
    self.textView.textColor = UIColor.lightGrayColor()
    self.textView.autocorrectionType = UITextAutocorrectionType.No
    self.textView.layer.cornerRadius = 6
    self.view.addSubview(textView)
Run Code Online (Sandbox Code Playgroud)

并在代表函数中:

func textViewDidBeginEditing(textView: UITextView) {

    if textView.textColor == UIColor.lightGrayColor() {
        textView.text = ""
        textView.textColor = UIColor.blackColor()
    }
}


func textViewDidEndEditing(textView: UITextView) {
    if textView.text.isEmpty {

        textView.text = "Agregue una descripción..."
        textView.textColor = UIColor.lightGrayColor()
    }
}
Run Code Online (Sandbox Code Playgroud)

我也尝试将字符串文本检查为nil:

if textView.text == nil …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch uitextview ios swift

1
推荐指数
1
解决办法
2149
查看次数

无限旋转UIView并暂停/停止动画,保持状态,并从当前状态继续旋转

我很难尝试暂停并从旋转的当前状态继续任何UIView旋转技术.

尝试:

CGAffineTransformRotate
CGAffineTransformMakeRotation
CATransform3DMakeRotation
CABasicAnimation
Run Code Online (Sandbox Code Playgroud)

基本上,如果我打电话view.layer.removeAllAnimations()或,layer.speed = 0他们都重置当前的旋转度.

还试图快照视图以使用图像而不是真正的旋转,但没有运气,因为快照忽略了旋转.

cocoa-touch rotation uiview ios swift

1
推荐指数
1
解决办法
726
查看次数

模拟器上的设备令牌请求没有响应

我是 iphone 技术的新手,现在我正在使用一个需要实现推送通知的应用程序。

我按照链接:

http://mobiforge.com/developing/story/programming-apple-push-notification-services#comment-7850

另外,使用了以下代码:

 NSLog(@"Registering for push notifications...");
    [[UIApplication sharedApplication]
  registerForRemoteNotificationTypes:
 (UIRemoteNotificationTypeAlert |
  UIRemoteNotificationTypeBadge | 
  UIRemoteNotificationTypeSound)];

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken 
{
    NSString *str = [NSString stringWithFormat:@"Device Token=%@",deviceToken];
    NSLog(str);
}

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err 
{ 
    NSString *str = [NSString stringWithFormat: @"Error: %@", err];
    NSLog(str);    
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{
    for (id key in userInfo) 
 {
        NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
    }    
}
Run Code Online (Sandbox Code Playgroud)

事情是,当我运行程序时,我应该根据代码在调试器窗口中获取设备令牌,而不是我收到如下错误:

" 注册错误。错误:Error Domain=NSCocoaErrorDomain Code=3010 "模拟器不支持远程通知" UserInfo=0x6e055a0 {NSLocalizedDescription=模拟器不支持远程通知} "

我应该如何解决这个问题?

请帮帮我。 …

push-notification apple-push-notifications ios ios-simulator

0
推荐指数
1
解决办法
2万
查看次数