小编A.R*_*Roe的帖子

在Swift 3中使用NSNumber和Integer值

我正在尝试将我的项目转换为Swift 3.0但是在使用NSNumber和时我有两个错误消息Integers.

无法将类型int指定为类型NSNumber

对于

//item is a NSManaged object with a property called index of type NSNumber 

var currentIndex = 0
 for item in self.selectedObject.arrayOfItems {
   item.index = currentIndex
   currentIndex += 1
 }
Run Code Online (Sandbox Code Playgroud)

甚至当我改变currentIndex一个类型NSNumber然后我得到错误

二进制运算符'+ ='不能应用于'NSNumber'和'Int'类型

所以然后我创建一个名为onetype 的属性NSNumber来添加,currentIndex但后来得到以下错误;

二进制运算符'+ ='不能应用于两个NSNumber操作数

&&我得到的第二个错误是

没有'+'候选者产生预期的上下文结果类型NSNumber

 let num: Int = 210
 let num2: Int = item.points.intValue
 item.points = num + num2
Run Code Online (Sandbox Code Playgroud)

在这里我只想尝试将210添加到points属性值,item是一个NSManagedObject.

所以基本上我遇到了一些问题,我想把数字添加到类型属性中NSNumber.我正在工作,NSNumber …

int nsnumber ios swift swift3

36
推荐指数
3
解决办法
4万
查看次数

如何设置关联域/通用链接

我试图在访问www.example.com/success时将用户重定向到已安装的应用程序,并在访问主页www.example.com时显示横幅。

\n

在我当前的植入中,网址不会重定向并打开应用程序,网站也不会显示横幅。

\n

我正在关注此处找到的文档https://developer.apple.com/documentation/safariservices/supporting_linked_domains

\n

我的网站很简单create-react-app,主页由 Firebase 托管。

\n

我做了以下事情:

\n
    \n
  1. 将关联域添加到签名和功能 - applinks:website.com/success
  2. \n
  3. apple-app-site-association将文件添加到/public/
  4. \n
  5. 修改 firebase.json 文件
  6. \n
  7. 链接到index.html中的文件
  8. \n
\n

我用什么来验证:

\n

https://branch.io/resources/aasa-validator/

\n

https://search.developer.apple.com/appsearch-validation-tool

\n

通过将www.example.com/success链接添加到注释并打开进行测试,它总是在 safari 中打开。我还尝试过重新安装应用程序并重新启动手机。

\n

苹果API验证

\n

我已将带有关联域的新应用程序版本上传到商店

\n

在此输入图像描述

\n

Branch.io

\n
{\n    "applinks": {\n        "apps": [],\n        "details": []\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

访问www.example.com/apple-app-site-association时

\n
\n

{ "activitycontinuation": { "apps": [ "team.com.example.com" ] },\n"applinks": { "apps": [], "details": [ { …

ios firebase reactjs applinks ios-universal-links

12
推荐指数
2
解决办法
3万
查看次数

无法将类型'() - > Void'的值转换为预期的参数类型'(( - - > Void)?'

我试图修改我的压轴错误,同时尝试转换为Swift 3,但我不确定为什么我得到错误

无法将类型'() - > Void'的值转换为预期的参数类型'(( - - > Void)?'

对于

 CATransaction.setCompletionBlock(completion)
Run Code Online (Sandbox Code Playgroud)

完整功能

fileprivate func deleteRowsAtIndexPaths(_ indexPaths: [IndexPath], withRowAnimation animation: UITableViewRowAnimation, duration: TimeInterval, completion:() -> Void) {
    CATransaction.begin()
    CATransaction.setCompletionBlock(completion) //Error
    UIView.animate(withDuration: duration) { () -> Void in
        self.deleteRows(at: indexPaths, with: animation)
    }
    CATransaction.commit()
}
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么我得到这个以及如何解决错误?

ios swift swift3

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

如何在Swift中使用UISplitViewController

所以我添加了UISplitViewController一个嵌入了一个项目的项目UITabBarController.

UISplitViewController有一个UINavigationController与他们自己的根控制器主控和细节的关系.

大师UINavigationController rootController有一个详细信息细节UINavigationController.

看这里:

在此输入图像描述

一切都很简单吧?现在在TableViewController中我做了以下几点;

class TableViewController: TableViewController, UISplitViewControllerDelegate {

var collapseDetailViewController: Bool  = false

override func viewDidLoad() {
    super.viewDidLoad()

    splitViewController?.delegate = self
}


override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    collapseDetailViewController = false
}

// MARK: - UISplitViewControllerDelegate

func splitViewController(splitViewController: UISplitViewController, collapseSecondaryViewController secondaryViewController: UIViewController, ontoPrimaryViewController primaryViewController: UIViewController) -> Bool {
    return false
}
Run Code Online (Sandbox Code Playgroud)

我也有一个UISplitViewController扩展并执行以下操作;

extension UISplitViewController: UISplitViewControllerDelegate {

public override func viewDidLoad() {
    self.extendedLayoutIncludesOpaqueBars = …
Run Code Online (Sandbox Code Playgroud)

uitabbarcontroller ipad uisplitviewcontroller ios swift

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

如何处理iOS 10中的UserNotifications操作

所以我可以安排这样的通知;

//iOS 10 Notification
if #available(iOS 10.0, *) {

    var displayDate: String {
        let dateFormatter = DateFormatter()
        dateFormatter.dateStyle = DateFormatter.Style.full
        return dateFormatter.string(from: datePicker.date as Date)
    }
    let notif = UNMutableNotificationContent()


    notif.title = "I am a Reminder"
    notif.subtitle = "\(displayDate)"
    notif.body = "Here's the body of the notification"
    notif.sound = UNNotificationSound.default()
    notif.categoryIdentifier = "reminderNotification"

    let today = NSDate()
    let interval = datePicker.date.timeIntervalSince(today as Date)

    let notifTrigger = UNTimeIntervalNotificationTrigger(timeInterval: interval, repeats: false)

    let request = UNNotificationRequest(identifier: "reminderNotif", content: notif, trigger: notifTrigger)

    UNUserNotificationCenter.current().add(request, …
Run Code Online (Sandbox Code Playgroud)

ios swift swift3 ios10 usernotificationsui

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

更新核心数据模型后出错 - 无法识别的选择器发送到实例

添加一个名为Unique Identifiermy Enitiy/ NSManagedObjectcalled 的字符串属性后,我收到以下错误Labels.然而,并不是Unique Identifier编制者不满意的.

2016-08-20 02:20:08.394 AN [22499:8730414] - [AN.Labels文件夹]:无法识别的选择器发送到实例0x7ffe907e1a80 2016-08-20 02:20:08.405 AN [22499:8730414]***终止应用程序由于未捕获的异常'NSInvalidArgumentException',原因:' - [AN.Labels文件夹]:无法识别的选择器发送到实例0x7ffe907e1a80'

这是我的NSManagedObject类

class Labels: NSManagedObject {

    @NSManaged var title: String?
    @NSManaged var details: String
    @NSManaged var date: NSDate?
    @NSManaged var uniqueIdentifier: NSString?

    @NSManaged var arrayOfFolders: [Folders]
    @NSManaged var folder: Folders?
    @NSManaged var folders: NSSet

    override func awakeFromFetch() {
        super.awakeFromFetch()
        self.regenerateFolders()
    }

    func regenerateFolders() {
        let date = NSSortDescriptor(key: "date", ascending: false)
        if let array = …
Run Code Online (Sandbox Code Playgroud)

core-data objective-c ios swift

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

放弃对Xcode项目的所有更改后恢复项目

所以我犯了一个巨大的男生错误,我没有将Xcode项目备份到外部驱动器.

Xcode项目工作时间为6-9个月,预计将在几周后发布.

我从未使用过Git/Github并正在经历树屋课程,所以我可以为项目设置工作流程.(是的,我new to development).

所以我到了创建回购的地步,Github但没有把项目交给回购.我去了本地提交但是出了错误,我不小心点击了丢弃所有更改.我已经丢失了我的应用程序和所有文件.

我去了垃圾桶,看到了一个似乎有所有文件的文件夹,但是我将文件夹拖到桌面并打开了项目,项目为空.

任何人都可以帮助我如何恢复我的项目?

PS:我有一个想法是恢复我上次备份的时间机器,并将我上次备份中的项目替换为从垃圾箱中恢复的项目.但我不知道这是否有效.最后一次备份是在一个月前,是的,我做了很多改动.

git xcode github ios

5
推荐指数
0
解决办法
494
查看次数

由于迁移到Swift 3后出现内存问题而终止

我正在使用Ensembles框架与iCloud同步数据.一切正常,直到我迁移到Swift 3.

该框架在Objective-C中,我的appDelegate功能已迁移到Swift 3; 从那以后我就遇到了问题.appDelegate.syncWithCompletion保存更改时,我会调用整个应用程序NSManagedObjects.

这是appDelegate功能

// MARK: Ensembles

var cloudFileSystem: CDECloudFileSystem!
var ensemble: CDEPersistentStoreEnsemble!

func syncWithCompletion(completion:@escaping (_ completed:Bool) -> Void) {

    if !ensemble.isLeeched {
        ensemble.leechPersistentStore { error in
            if error != nil {
                print("cannot leech \(error!.localizedDescription)")
                completion(false)
            }
            else {
                print("leached!!")
                completion(true)
            }
        }
    }
    else {
        ensemble.merge{ error in
            if error != nil {
                print("cannot merge \(error!.localizedDescription)")
                completion(false)
            }
            else {
                print("merged!!")
                completion(true)
                //NSNotificationCenter.defaultCenter().postNotificationName("Updated-DB", object: nil)
            }
        }
    }
} …
Run Code Online (Sandbox Code Playgroud)

objective-c ios swift ensembles

5
推荐指数
0
解决办法
1017
查看次数

调用初始化程序时更改属性值

这是我在此处发现的上一个问题的后续跟进

我正在使用MarkdownTextView向a添加基本降价UITextView.它TextView是的子类MarkdownTextView.

在我使用复制和粘贴时的上一个问题中,我收到以下错误

致命错误:对MarkdownTextStorage类使用未实现的初始化程序'init()'

直到我将以下初始化程序添加到MarkdownTextStorage类中

public override convenience init() {
    self.init(attributes: MarkdownAttributes())
}

public init(attributes: MarkdownAttributes = MarkdownAttributes()) {
    self.attributes = attributes
    super.init()
    commonInit()

    if let headerAttributes = attributes.headerAttributes {
        addHighlighter(MarkdownHeaderHighlighter(attributes: headerAttributes))
    }
    addHighlighter(MarkdownLinkHighlighter())
    addHighlighter(MarkdownListHighlighter(markerPattern: "[*+-]", attributes: attributes.unorderedListAttributes, itemAttributes: attributes.unorderedListItemAttributes))
    addHighlighter(MarkdownListHighlighter(markerPattern: "\\d+[.]", attributes: attributes.orderedListAttributes, itemAttributes: attributes.orderedListItemAttributes))

    // From markdown.pl v1.0.1 <http://daringfireball.net/projects/markdown/>

    // Code blocks
    addPattern("(?:\n\n|\\A)((?:(?:[ ]{4}|\t).*\n+)+)((?=^[ ]{0,4}\\S)|\\Z)", attributes.codeBlockAttributes)

    // Block quotes
    addPattern("(?:^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+", attributes.blockQuoteAttributes)

    // Se-text style …
Run Code Online (Sandbox Code Playgroud)

ios swift

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

使用Swift为NSDate添加天/小时

我知道这是一个非常基本的问题,我知道我可能找不到答案,因为我没有问正确的问题但是我怎样才能更改NSDate值?

例如,我有一个date属性设置为a的日期,datePicker我想创建一个新属性,它是属性的前一天date,另一个属性是一小时前.

nsdate swift

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