小编Mat*_*son的帖子

如果条目已存在,如何防止覆盖DynamoDB项目

我试图编写一个lambda函数来向DynamoDB表添加新数据.从阅读文档:

http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#put-property PUT方法:"通过委派给AWS创建新项目或用新项目替换旧项目.DynamoDB.putItem()".

除了在'put'之前检查一个对象之外,当尝试PUT时,是否存在一个设置或标志以使对象失败?

我可以看到

params -> Expected -> Exists (Bool)
Run Code Online (Sandbox Code Playgroud)

但无法看到有关此功能的任何文档.

什么是阻止项目覆盖的最佳架构(或禁止)?

Query the table first and if no item exists then add the item
Run Code Online (Sandbox Code Playgroud)

要么

Attempt to insert the item and on failure because of duplicate entry report this back? (Is there a way to prevent item overwrite?)
Run Code Online (Sandbox Code Playgroud)

lambda amazon-web-services amazon-dynamodb

13
推荐指数
3
解决办法
5587
查看次数

Swift使用Contacts Framework,使用电话号码搜索以获取名称和用户图像

我有一个返回格式为电话号码的API:+ 1415xxxxxxx(E164)

现在这些数字被放入UITableView的Cell中并按预期显示,但是我希望能够搜索手机上的用户联系人以查看是否存在匹配 - 如果是这样也会传回名字,姓氏和已知照片.

看看Apple页面(https://developer.apple.com/library/watchos/documentation/Contacts/Reference/Contacts_Framework/index.html)我需要

 import ContactsUI
Run Code Online (Sandbox Code Playgroud)

但是我不确定,我是否将contactDB加载到字典中然后进行搜索?我可以通过名称找到很多东西,而不是通过数字搜索:

  let predicate = CNContact.predicateForContactsMatchingName("Sam") 
Run Code Online (Sandbox Code Playgroud)

我试图找到一个我可以调用的函数,使用PhoneNumber进行搜索并返回FirstName,FamilyName和Image.

  func searchForContactUsingNumber(PhoneNumber: String)
 {

 // Search Via phoneNumber
  let store = CNContactStore()
  let contacts = try store.unifiedContactsMatchingPredicate(CNContact.predicateForContactsMatchingPhoneNumber(PhoneNumber), keysToFetch:[CNContactGivenNameKey, CNContactFamilyNameKey,CNContactImageData])

  return FirstName, GivenName,UIImage

 }
Run Code Online (Sandbox Code Playgroud)

我觉得我正在倒退但不确定前进的方向..任何想法?

ios swift cncontact contacts-framework

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

Swift根据时间戳显示时间或日期

我有一个返回数据的API,包括该记录的时间戳.在swift中我加载了timestamp元素并将其转换为double,然后可以将其转换为时间.如果记录的日期是今天,我希望能够返回时间,如果记录不是今天,我希望返回日期.见下文:

        let unixTimeString:Double = Double(rowData["Timestamp"] as! String)!
        let date = NSDate(timeIntervalSince1970: unixTimeString) // This is on EST time and has not yet been localised.
        var dateFormatter = NSDateFormatter()
        dateFormatter.timeStyle = .ShortStyle
        dateFormatter.doesRelativeDateFormatting = true
        // If the date is today then just display the time, if the date is not today display the date and change the text color to grey.
        var stringTimestampResponse = dateFormatter.stringFromDate(date)
        cell.timestampLabel.text = String(stringTimestampResponse)
Run Code Online (Sandbox Code Playgroud)

我是否使用NSCalendar查看"日期"是否为今天然后做某事?那么你如何本地化时间以使其对用户而不是服务器时间更正?

nsdate nsdateformatter nscalendar swift

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

SwiftUI 从数组中返回不同类型的对象

我有一个包含不同类型消息的数组:

let chatMessagesArray = [
    TextMessage(direction: "Incoming", timestamp: 1589463871, senderID: "Bob", destinationID: "Sally", message: "I was sent this message", deliveryStatus: "Delivered", deliveryTimestamp: 1589463871),
    TextMessage(direction: "Outbound", timestamp: 1589467569, senderID: "Sally", destinationID: "Bob", message: "I sent this message", deliveryStatus: "Delivered", deliveryTimestamp: 1589467622),
    ImageMessage(direction: "Incoming", timestamp: 1589485467, senderID: "Bob", destinationID: "Sally", imageURL: "http://Image.Full.URL", thumbnailURL: "https://thumbnail.image.url", deliveryStatus: "Delivered", deliveryTimestamp:1589485467),
] as [Any] <-- Is Any the best choice?
Run Code Online (Sandbox Code Playgroud)

每种类型的消息都有自己的视图:

struct TextMessageView: View {
    var currentMessage: TextMessage
    var body: some View {
        HStack(alignment: .bottom, spacing: …
Run Code Online (Sandbox Code Playgroud)

list swift swiftui

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