<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nrf52 iOS sdk14.2 swift - writeValue works for UInt8 but not UInt16</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/33655/nrf52-ios-sdk14-2-swift---writevalue-works-for-uint8-but-not-uint16</link><description>Hoping to get some help. Using swift3 and xcode 9.3. 
 I can write data from iPhone back to nrf52 peripheral fine if it is a Dbl. 
 When I try to write a UInt16, it crashes. 
 Here is the code that works for Dbl: 
 
 
 Here is my code I tried for UInt16</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 23 Apr 2018 13:58:22 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/33655/nrf52-ios-sdk14-2-swift---writevalue-works-for-uint8-but-not-uint16" /><item><title>RE: nrf52 iOS sdk14.2 swift - writeValue works for UInt8 but not UInt16</title><link>https://devzone.nordicsemi.com/thread/129371?ContentTypeID=1</link><pubDate>Mon, 23 Apr 2018 13:58:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0452848a-a407-40dd-9eac-6f234fcc19a7</guid><dc:creator>Bryan H</dc:creator><description>&lt;p&gt;I fixed this by splitting the UInt16 into 2 Uint8:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="java"&gt;let UInt8Value0 = reading &amp;gt;&amp;gt; 8
let UInt8Value1 = Uint8(reading &amp;amp; 0x00ff)
let bytes = [Uint8] = [ UInt8Value1, UInt8Value0 ]
let data = Data(bytes:bytes)
self.bluetoothManager.connectedPeripheral?.writeValue(data, for: self.rowCharacteristic!, type: CBCharacteristicWriteType.withResponse)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>