CloudKit-CKRecord.ID可接受的recordName吗?

时间:2019-02-28 07:25:58

标签: swift cloudkit ckrecord

我已经编写了一种将记录保存在自定义区域中的方法,它似乎按预期工作。不过,我不确定的一件事是<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> <button id="btnOrig">Show Original Table</button> <div id="orig_table"> <table class="table" id="tableUnit" style="width: 100%;"> <thead> <tr> <th style="width: 7em;"><strong>Generasi</strong></th> <th style="width: 20em;"><strong>Unit Code</strong></th> <th style="width: 20em;"><strong>Agent Code Unit</strong></th> <th style="width: 6em;"><strong>Unit Name</strong></th> <th style="width: 6em;" class="center"><strong>No.</strong></th> <th style="width: 5em;"><strong>Agent Code</strong></th> <th style="width: 15em;"><strong>Agent Name</strong></th> <th style="width: 15em;"><strong>VOC</strong></th> <th style="width: 15em;"><strong>KPM</strong></th> <th style="width: 15em;" class="right"><strong>Case</strong></th> <th style="width: 15em;" class="right"><strong>ALP</strong></th> <th></th> </tr> </thead> <tbody> <tr bgcolor="#ededf9"> <td colspan="8" class="right"><strong>SUB TOTAL G-0</strong></td> <td></td> <td class="right"><strong>0</strong></td> <td class="right"><strong>0</strong></td> <td></td> </tr> <tr> <td colspan="12"></td> </tr> </tbody> <tbody> <tr> <td>G-1</td> <td>A6011</td> <td>00923917</td> <td>FRANSISKA YULIANA B.D.</td> <td>1</td> <td>00905445</td> <td>NESTI RAHAYU</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">1</td> <td class="right">6.000.000</td> <td></td> </tr> <tr> <td>G-1</td> <td>A6011</td> <td>00923917</td> <td>FRANSISKA YULIANA B.D.</td> <td>2</td> <td>00905448</td> <td>AISYAH</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">2</td> <td class="right">30.000.000</td> <td></td> </tr> <tr> <td>G-1</td> <td>A6011</td> <td>00923917</td> <td>FRANSISKA YULIANA B.D.</td> <td>3</td> <td>00905454</td> <td>ADYANTA YOGA PRADANA</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">1</td> <td class="right">6.000.000</td> <td></td> </tr> <tr> <td>G-1</td> <td>A7924</td> <td>00947903</td> <td>MELVA SUPARDI</td> <td>4</td> <td>00947903</td> <td>MELVA SUPARDI</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">1</td> <td class="right">6.000.000</td> <td></td> </tr> <tr bgcolor="#ededf9"> <td colspan="8" class="right"><strong>SUB TOTAL G-1</strong></td> <td></td> <td class="right"><strong>5</strong></td> <td class="right"><strong>48.000.000</strong></td> <td></td> </tr> <tr> <td colspan="12"></td> </tr> </tbody> <tbody> <tr> <td>G-2</td> <td>A5974</td> <td>00923389</td> <td>ALI WIDODO</td> <td>1</td> <td>00918088</td> <td>JOHN HENDRI</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">2</td> <td class="right">12.000.000</td> <td></td> </tr> <tr> <td>G-2</td> <td>A5993</td> <td>00923678</td> <td>PATENSAROHA PANJAITAN</td> <td>2</td> <td>00924255</td> <td>PURNAMA MARINTAN</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">4</td> <td class="right">28.800.000</td> <td></td> </tr> <tr> <td>G-2</td> <td>A8603</td> <td>00966488</td> <td>RISANG RUDI PERMADI</td> <td>3</td> <td>00966488</td> <td>RISANG RUDI PERMADI</td> <td>SM</td> <td>SMG043</td> <td class="right">2</td> <td class="right">31.200.000</td> <td></td> </tr> <tr bgcolor="#ededf9"> <td colspan="8" class="right"><strong>SUB TOTAL G-2</strong></td> <td></td> <td class="right"><strong>8</strong></td> <td class="right"><strong>72.000.000</strong></td> <td></td> </tr> <tr> <td colspan="12"></td> </tr> </tbody> <tbody> <tr> <td>G-3</td> <td>A2190</td> <td>00906041</td> <td>LIESTYANINGSIH PRASETYO</td> <td>1</td> <td>00906041</td> <td>LIESTYANINGSIH PRASETYO</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">1</td> <td class="right">6.000.000</td> <td></td> </tr> <tr> <td>G-3</td> <td>A6659</td> <td>00910973</td> <td>FERMOLINA</td> <td>2</td> <td>00910973</td> <td>FERMOLINA</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">4</td> <td class="right">73.000.000</td> <td></td> </tr> <tr> <td>G-3</td> <td>A5974</td> <td>00923389</td> <td>ALI WIDODO</td> <td>3</td> <td>00911258</td> <td>CAROTRIANA HARTIANI</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">2</td> <td class="right">8.400.000</td> <td></td> </tr> <tr> <td>G-3</td> <td>A7824</td> <td>00913029</td> <td>YULI PURWANTI</td> <td>4</td> <td>00913029</td> <td>YULI PURWANTI</td> <td>SM</td> <td>SMG043</td> <td class="right">1</td> <td class="right">4.800.000</td> <td></td> </tr> <tr> <td>G-3</td> <td>A8603</td> <td>00966488</td> <td>RISANG RUDI PERMADI</td> <td>5</td> <td>00925635</td> <td>RICHA DEWI AZDANI</td> <td>SM</td> <td>SMG043</td> <td class="right">4</td> <td class="right">18.000.000</td> <td></td> </tr> <tr> <td>G-3</td> <td>A2006</td> <td>00905496</td> <td>MARYANAH</td> <td>6</td> <td>00941248</td> <td>ROCHIMI DIAN PUSPITASARI</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">2</td> <td class="right">9.600.000</td> <td></td> </tr> <tr> <td>G-3</td> <td>A7240</td> <td>00942942</td> <td>SOE ESTI MURNIATI</td> <td>7</td> <td>00942942</td> <td>SOE ESTI MURNIATI</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">3</td> <td class="right">23.040.000</td> <td></td> </tr> <tr> <td>G-3</td> <td>A8053</td> <td>00951213</td> <td>A. M. GANDA MARPAUNG</td> <td>8</td> <td>00951213</td> <td>A. M. GANDA MARPAUNG</td> <td>JB3</td> <td>JAM707</td> <td class="right">1</td> <td class="right">4.800.000</td> <td></td> </tr> <tr> <td>G-3</td> <td>A2006</td> <td>00905496</td> <td>MARYANAH</td> <td>9</td> <td>00953857</td> <td>MOCH KEMAL ASYAF</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">2</td> <td class="right">36.000.000</td> <td></td> </tr> <tr> <td>G-3</td> <td>A2006</td> <td>00905496</td> <td>MARYANAH</td> <td>10</td> <td>00968671</td> <td>GITA NELWAN</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">1</td> <td class="right">12.000.000</td> <td></td> </tr> <tr bgcolor="#ededf9"> <td colspan="8" class="right"><strong>SUB TOTAL G-3</strong></td> <td></td> <td class="right"><strong>21</strong></td> <td class="right"><strong>195.640.000</strong></td> <td></td> </tr> <tr> <td colspan="12"></td> </tr> </tbody> <tbody> <tr> <td>G-4</td> <td>A4040</td> <td>00909748</td> <td>KARINA</td> <td>1</td> <td>00909748</td> <td>KARINA</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">2</td> <td class="right">54.000.000</td> <td></td> </tr> <tr> <td>G-4</td> <td>A6091</td> <td>00910151</td> <td>NONAH SUHANAH</td> <td>2</td> <td>00910517</td> <td>ALFIAN IDRUS</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">1</td> <td class="right">6.000.000</td> <td></td> </tr> <tr> <td>G-4</td> <td>A5974</td> <td>00923389</td> <td>ALI WIDODO</td> <td>3</td> <td>00912869</td> <td>ROHMAT</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">1</td> <td class="right">12.060.000</td> <td></td> </tr> <tr> <td>G-4</td> <td>A6659</td> <td>00910973</td> <td>FERMOLINA</td> <td>4</td> <td>00925358</td> <td>ANDRIYANI</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">1</td> <td class="right">8.400.000</td> <td></td> </tr> <tr> <td>G-4</td> <td>A6789</td> <td>00909167</td> <td>WAHYU RIDWAN NUGROHO</td> <td>5</td> <td>00938577</td> <td>ACHMAD TAUFIK</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">1</td> <td class="right">4.800.000</td> <td></td> </tr> <tr> <td>G-4</td> <td>A8822</td> <td>00944260</td> <td>DESSY RANTAU WIDIASARI</td> <td>6</td> <td>00944260</td> <td>DESSY RANTAU WIDIASARI</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">1</td> <td class="right">6.000.000</td> <td></td> </tr> <tr> <td>G-4</td> <td>A8896</td> <td>00946599</td> <td>ILHAM WAHYUDIN</td> <td>7</td> <td>00946599</td> <td>ILHAM WAHYUDIN</td> <td>SB</td> <td>SKB008</td> <td class="right">1</td> <td class="right">6.000.000</td> <td></td> </tr> <tr> <td>G-4</td> <td>A6091</td> <td>00910151</td> <td>NONAH SUHANAH</td> <td>8</td> <td>00947779</td> <td>YENNI CHRISTINA</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">1</td> <td class="right">12.000.000</td> <td></td> </tr> <tr> <td>G-4</td> <td>A7204</td> <td>00941979</td> <td>MANUELA R SIAGIAN</td> <td>9</td> <td>00959611</td> <td>LAURENTIA DYAH IKA G</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">1</td> <td class="right">10.400.000</td> <td></td> </tr> <tr> <td>G-4</td> <td>A2042</td> <td>00905588</td> <td>HENY BAYU SAFITRI</td> <td>10</td> <td>00965234</td> <td>YASAN</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">1</td> <td class="right">12.000.000</td> <td></td> </tr> <tr> <td>G-4</td> <td>A6659</td> <td>00910973</td> <td>FERMOLINA</td> <td>11</td> <td>00968489</td> <td>ANDRE PERBAWA</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">3</td> <td class="right">36.000.000</td> <td></td> </tr> <tr bgcolor="#ededf9"> <td colspan="8" class="right"><strong>SUB TOTAL G-4</strong></td> <td></td> <td class="right"><strong>14</strong></td> <td class="right"><strong>167.660.000</strong></td> <td></td> </tr> <tr> <td colspan="12"></td> </tr> </tbody> <tbody> <tr> <td>G-5</td> <td>A2157</td> <td>00905917</td> <td>SYARIFAH</td> <td>1</td> <td>00905917</td> <td>SYARIFAH</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">4</td> <td class="right">30.000.000</td> <td></td> </tr> <tr> <td>G-5</td> <td>A2043</td> <td>00905590</td> <td>BUNGAIDAL ADKHIA</td> <td>2</td> <td>00911669</td> <td>ZULFIKAR</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">2</td> <td class="right">18.000.000</td> <td></td> </tr> <tr> <td>G-5</td> <td>A8896</td> <td>00946599</td> <td>ILHAM WAHYUDIN</td> <td>3</td> <td>00914524</td> <td>RITAWATI</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">3</td> <td class="right">13.200.000</td> <td></td> </tr> <tr> <td>G-5</td> <td>A8896</td> <td>00946599</td> <td>ILHAM WAHYUDIN</td> <td>4</td> <td>00923652</td> <td>DEDEN AMARULLAH</td> <td>SB</td> <td>SKB008</td> <td class="right">1</td> <td class="right">4.200.000</td> <td></td> </tr> <tr> <td>G-5</td> <td>A6916</td> <td>00937689</td> <td>SUDIRMAN</td> <td>5</td> <td>00937689</td> <td>SUDIRMAN</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">1</td> <td class="right">6.000.000</td> <td></td> </tr> <tr> <td>G-5</td> <td>A8199</td> <td>00944267</td> <td>DEWI KARTINI</td> <td>6</td> <td>00944267</td> <td>DEWI KARTINI</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">1</td> <td class="right">30.000.000</td> <td></td> </tr> <tr> <td>G-5</td> <td>A8131</td> <td>00954706</td> <td>HENDRA SURYA</td> <td>7</td> <td>00954706</td> <td>HENDRA SURYA</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">2</td> <td class="right">15.600.000</td> <td></td> </tr> <tr> <td>G-5</td> <td>A6307</td> <td>00911807</td> <td>BERTA M PURBA</td> <td>8</td> <td>00964680</td> <td>DANIEL</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">1</td> <td class="right">6.000.000</td> <td></td> </tr> <tr> <td>G-5</td> <td>A8822</td> <td>00944260</td> <td>DESSY RANTAU WIDIASARI</td> <td>9</td> <td>00967703</td> <td>YANTI ARIANI</td> <td>TN1</td> <td>JKT0A1</td> <td class="right">2</td> <td class="right">18.000.000</td> <td></td> </tr> <tr> <td>G-5</td> <td>A7824</td> <td>00913029</td> <td>YULI PURWANTI</td> <td>10</td> <td>00968122</td> <td>NOVIA BETSY CLARISSA</td> <td>SM</td> <td>SMG043</td> <td class="right">1</td> <td class="right">24.000.000</td> <td></td> </tr> <tr bgcolor="#ededf9"> <td colspan="8" class="right"><strong>SUB TOTAL G-5</strong></td> <td></td> <td class="right"><strong>18</strong></td> <td class="right"><strong>165.000.000</strong></td> <td></td> </tr> <tr> <td colspan="12"></td> </tr> </tbody> <tfoot> <tr bgcolor="#ededf9"> <td colspan="8" class="right"><strong>GRAND TOTAL</strong></td> <td></td> <td class="right"><strong>66</strong></td> <td class="right"><strong>648.300.000</strong></td> <td></td> </tr> </tfoot> </table> </div><!-- #orig_table --> <h2>Final Table:</h2> <div class="finalTable"></div> CKRecord.ID。现在,我只使用一个recordName字符串。是否有分配UUID的首选方法?当前的CloudKit示例非常稀缺,并且CK文档中相当不错的一部分似乎已过时。谢谢。

recordName

3 个答案:

答案 0 :(得分:1)

从我的角度来看,它在CKRecord.ID的文档中非常清楚:

  

记录ID对象由名称字符串和区域ID组成。名称字符串是长度不超过255个字符的ASCII字符串。对于自动创建的记录,ID名称字符串基于UUID,因此保证是唯一的。创建自己的记录ID对象时,只要每个名称在指定区域内都是唯一的,您就可以自由使用对您的应用或用户具有更多含义的名称。例如,您可以使用文档名称作为名称字符串。

答案 1 :(得分:1)

我同意UUID是理想的。示例:

JupyterLab

但是,重要的是不要尝试用无效字符或零长度字符串创建一个。结果是致命错误!因此,当从不受信任的源加载它们时(例如从服务器输出进行解析),我使用如下安全功能:

let newId = CKRecord.ID(recordName: UUID().uuidString)

用法:

extension CKRecord.ID {     
    public static func fromUntrusted(_ string: String?) -> CKRecord.ID? {
        guard let string = string else { return nil }
        guard let _ = string.data(using: .ascii, allowLossyConversion: false) else { return nil }
        guard string.count > 0 && string.count < 255 else { return nil }
        return CKRecord.ID(recordName: string)
    }
}

答案 2 :(得分:0)

根据我的经验,最好从记录键(即必须是唯一的字段组合)中生成记录名称。

这样,即使您错误地尝试两次添加同一记录,也可以保证唯一性。

AFAIK,没有其他方法可以使CloudKit中的某些字段组合唯一。