Author Topic: IOS APPS in swift language  (Read 22342 times)

wiesnerhealth

  • RFduino Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
IOS APPS in swift language
« on: June 17, 2014, 11:32:02 AM »
As you guys know, apple update their programming language from Objective C to Swift, which is much easier to learn than the previous one.

I would like to know if you guys are planning to update the Apps to this new language??

Thanks,

skydrew

  • RFduino Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: IOS APPS in swift language
« Reply #1 on: June 20, 2014, 02:04:20 AM »
That would be great! +1

notsolinear

  • RFduino Jr. Member
  • **
  • Posts: 52
  • Karma: +3/-0
    • View Profile
Re: IOS APPS in swift language
« Reply #2 on: June 23, 2014, 11:53:38 AM »
It's definitely not a bad idea to get started on such migrations sooner rather than later.  Apple is nothing if not relentless about getting rid of old baggage, and soon enough there will be some new SDK feature or version of Xcode that begins to deprecate support for this or that.

That said, having read the whole Swift ebook and doing Objective-C based programming for a living I disagree a bit with the assumption that Swift is easier. In terms of language features available to programmers, Swift has a TON of new concepts in addition to everything obj-c had. Yes, you can write simple Swift code where the syntax will appear much more like PHP or Javascript and thus be more familiar to a broad set of people.  However at the same time there are also much more complex ideas like optional variables, way more complicated switch cases, enums that have instance methods, functions that return tuples, functions that can be written at least 3 different ways, and almost all of the data types are inferred so the programmer has to keep track in the head of what types they're working with as opposed to having it written out explicitly.

Really, my impression after reading the Swift language reference is that it's a "Pro" version of Objective-C.  If you really understand how Objective-C works then it allows you to write much less text to achieve the same result, but if you don't understand what it is the compiler is doing for you, you will have a very hard time debugging problems.

lsnyman

  • RFduino Sr. Member
  • ****
  • Posts: 144
  • Karma: +1/-0
    • View Profile
Re: IOS APPS in swift language
« Reply #3 on: June 30, 2014, 02:17:26 PM »
My Hardware oriented brain is too stupid for Objective C, so that is not good news for me  :-\

maverik0106

  • RFduino Jr. Member
  • **
  • Posts: 59
  • Karma: +0/-0
    • View Profile
Re: IOS APPS in swift language
« Reply #4 on: October 13, 2014, 12:46:59 PM »
I have actually had a bit of a break recently and I am able to see a list of BLE devices ... i.e. the RFDuino on a TableView using Storyboards and iOS 8

Swift seems to make it so much easier and I am not using the RFDuino library whatsoever, all you have to import is CoreBluetooth to the swift file and it practically does everything for you.

You do need to read a lot, but I'm working on getting it to work first then I'll post some examples.
I am able to use storyboards and design a specific user interface which makes it so much simpler and better suited to anyone's needs.
Functionality wise, I'm only able to press the "scan" button, and make the BLE devices appear in a tableView, finally to be able to see the RSSI, UUID and other information about the device when pressed on.

However I still need to implement the connect to device functions and find a way to read/write data to the RFDuino....
If anyone is interested in helping that would be much appreciated and obviously faster for development of our own apps...

But this is truly quite a few hours of research and learning swift (still a noob i.e. swift just came a few weeks ago)

The test still has bugs obviously, but am working on getting rid of them soon...


mrwilljackson

  • RFduino Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: IOS APPS in swift language
« Reply #5 on: November 28, 2014, 03:29:35 AM »
^^ +1 to a swift example please  8)

mrwilljackson

  • RFduino Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: IOS APPS in swift language
« Reply #6 on: November 29, 2014, 01:46:56 AM »
So I've found a project on GitHub by Michael Teeuw - nRF8001 library in Swift - https://github.com/MichMich/nRF8001-Swift#properties

If you open this project and amend NRFManager.swift lines 459 onwards like so:
Code: [Select]
// MARK: Class Methods
extension UARTPeripheral {
    class func uartServiceUUID() -> CBUUID {
        return CBUUID(string:"2220")
    }
   
    class func txCharacteristicsUUID() -> CBUUID {
        return CBUUID(string:"2222")
    }
   
    class func rxCharacteristicsUUID() -> CBUUID {
        return CBUUID(string:"2221")
    }
   
    class func deviceInformationServiceUUID() -> CBUUID{
        return CBUUID(string:"2220")
    }
   
    class func hardwareRevisionStringUUID() -> CBUUID{
        return CBUUID(string:"2220")
    }
}

the project compiles and runs and you can connect, disconnect (without crashing the app) and view incoming data in the console log coming from the rfduino BLE.

In my project I'm sending a float value from a pressure sensor to the iPhone like this:
Code: [Select]
   
RFduinoBLE.sendFloat(pressure);
RFduinoBLE.send(99);

But when its displayed back on the console window in xCode the values are displayed as follows:

Code: [Select]
UARTPeripheral: Did Update Value For Characteristic
UARTPeripheral: Recieved: <00a465be>
UARTPeripheral: Did Update Value For Characteristic
UARTPeripheral: Recieved: <63>
UARTPeripheral: Did Update Value For Characteristic
UARTPeripheral: Recieved: <00a465be>
UARTPeripheral: Did Update Value For Characteristic
UARTPeripheral: Recieved: <63>

noob alert  ;D
Question: So are these hex values rather than the float and int value of 99? the 99 is shown as 63, the other value should be between -1 and 1 as they're background readings from the pressure sensor.

Question 2: can I convert them back to the int and float values that i need?

I have a nasty feeling that I have the data types mixed up, but I'm not sure how to resolve it. (I have a little experience with objective C and not much with Swift) Thanks in advance for any assistance ;-)

cheers
Will

tolson

  • Global Moderator
  • *****
  • Posts: 870
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: IOS APPS in swift language
« Reply #7 on: November 29, 2014, 10:21:10 AM »
Hi Will,

It gets confusing when you ask the same questions in different topics.
Here's the answer...
http://forum.rfduino.com/index.php?topic=831.msg3367#msg3367

maverik0106

  • RFduino Jr. Member
  • **
  • Posts: 59
  • Karma: +0/-0
    • View Profile
Re: IOS APPS in swift language
« Reply #8 on: November 29, 2014, 05:50:51 PM »
Hi Tolson,

would you be able to provide a sample answer on how to answer his second question tho? I'm also interested in knowing and it seems like you may know the answer.

Thanks!

tolson

  • Global Moderator
  • *****
  • Posts: 870
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: IOS APPS in swift language
« Reply #9 on: November 29, 2014, 06:57:28 PM »
Hi Tolson,

would you be able to provide a sample answer on how to answer his second question tho? I'm also interested in knowing and it seems like you may know the answer.

Thanks!

I don't have access to iStuff. My iMAC hardware is no longer supported or upgradable past Snow Leopard. So I've baled on iStuff. So I can't help with how iStuff uses Swift or Storyboards or any of the iStuff centric ways of programming an app. I'm surprised there aren't more iStuff guru's volunteering some answers.

i can suggest that the best way to learn though is to solve the problem. Study source from anywhere you can. The answer is not RFduino specific, but iStuff specific.

« Last Edit: November 29, 2014, 07:04:48 PM by tolson »

maverik0106

  • RFduino Jr. Member
  • **
  • Posts: 59
  • Karma: +0/-0
    • View Profile
Re: IOS APPS in swift language
« Reply #10 on: November 29, 2014, 07:07:06 PM »
Thanks,

maybe not in language/coding... but maybe in the logic of how to convert the 4-byte endian hex values back into a 32bit Int? bitwise operation was never my forté....

I guess I should read a microprocessor's book and read all about bit operations...

thanks again

tolson

  • Global Moderator
  • *****
  • Posts: 870
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: IOS APPS in swift language
« Reply #11 on: November 29, 2014, 07:28:30 PM »
Thanks,

maybe not in language/coding... but maybe in the logic of how to convert the 4-byte endian hex values back into a 32bit Int? bitwise operation was never my forté....

I guess I should read a microprocessor's book and read all about bit operations...

thanks again
No bitwise operations are necessary.
If the 4 byte value is suppose to be integer, then it is either signed or unsigned.
The question was about  float value appearing as 4 bytes. Should just be able to assign the buffer as type float.

If on the other hand you want to do array operations, I guess you could do it something like this in 'C'...
Code: [Select]
float float_var;
byte *f_p = (byte*)&float_var;
f_p[0] = 0x00;
f_p[1] = 0xa4;
f_p[2] = 0x65;
f_p[3] = 0xbe;

println(float_var);

maverik0106

  • RFduino Jr. Member
  • **
  • Posts: 59
  • Karma: +0/-0
    • View Profile
Re: IOS APPS in swift language
« Reply #12 on: November 29, 2014, 07:36:30 PM »
Hi

I'll have to process this, however thanks a lot for your quick response...

Well I guessed my information was also a 4-byte float since the code from RFduino is sending a float.

Thanks a lot I appreciate it

tolson

  • Global Moderator
  • *****
  • Posts: 870
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: IOS APPS in swift language
« Reply #13 on: November 29, 2014, 08:09:14 PM »
The RFduino examples give all the source code for iOS to work with the various apps. Find the one that receives a float buffer and go from there. I think the temperature one uses floats. Since they've already done one that sends and receives floats, you already have a template to work from. No need to mess around figuring out endianess that they've already figured out. Now if only there was source for all the same apps for Android.

maverik0106

  • RFduino Jr. Member
  • **
  • Posts: 59
  • Karma: +0/-0
    • View Profile
Re: IOS APPS in swift language
« Reply #14 on: November 29, 2014, 08:24:35 PM »


Yeah already tried that....

The implementation is quite different now with the new programming language... I guess I could import the file as an external library but I wanted to program it all in swift and avoid writing/reusing any objective-c since I never really finished learning it.

Thanks for the help!

 

anything