gpt4 book ai didi

swift - 快速分割任意对象

转载 作者:行者123 更新时间:2023-11-30 10:13:27 26 4
gpt4 key购买 nike

我想获取我的区域设置通知的用户信息。我这样做是这样的:

var app:UIApplication = UIApplication.sharedApplication()
for oneEvent in app.scheduledLocalNotifications {
var notification = oneEvent as! UILocalNotification
ate = gregorian.dateFromComponents(comps)!

var OldUUID = notification.userInfo
}
}

结果是:

{UUID = WhmMbGrCkJ;}"

但我只想要这部分:WhmMbGrCkJ我尝试这样的事情:

        var OldUUID = notification.userInfo
var OldUUIDSplit = OldUUID.componentsSeparatedByString("=")
var OldUUIDSplit2 = OldUUIDSplit[1].stringByReplacingOccurrencesOfString(" ", withString: "")
var OldUUIDSplit3 = OldUUIDSplit2.componentsSeparatedByString(";")
var NewOldUUID = OldUUIDSplit3[0]

我收到此错误:

Cannot invoke 'componentsSeparatedByString' with an argument list of type '(String)'

如何解决?

最佳答案

这应该可以完成工作。 userInfo 只是一个字典,因此您可以通过键获取值:

if let dict = notification.userInfo, OldUUID = dict["UUID"] {
println("\(OldUUID)")
}

关于swift - 快速分割任意对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31608976/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com