Pages: [1]   Go Down
Author Topic: Apple swift  (Read 1836 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 291
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm reading up on apple's new C language, Swift. It can return from a function multiple values with any combination of data types.

That is all. I'm sold!
Logged

Global Moderator
Italy
Offline Offline
Brattain Member
*****
Karma: 332
Posts: 22817
Logic is my way
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The Swift programming language is the successor of Objective-C, I think it's not a C-family member but a C++-family member.
It has been developed to update the old-fashioned Obj-C and to result more easy and clear in use than it.
I didn't try it yet but voices on its performances are constrasting: someone says that it's faster than Obj-C, someone else says it's slower...
The only thing that it's clear is that it's an Apple-only language, due to the fact that it will run only on MAC/iOS.
Logged


0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 291
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yeah, it's iOS, OS X only which is a shame. It should be platform independent.
Logged

Global Moderator
Italy
Offline Offline
Brattain Member
*****
Karma: 332
Posts: 22817
Logic is my way
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It's very friendly, it has a syntax that remembers me that one of Ruby.
Logged


0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 291
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm skimming through the use manual now. It's simple and powerful. It takes a little getting use to even for me since I know objective C.
Logged

0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 291
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I see a lot of rookie mistakes here on the forum like
Code:
if (x = 1)
C allows for this without throwing any errors. In swift this is illegal and will error. Neat change.
Logged

Global Moderator
Italy
Offline Offline
Brattain Member
*****
Karma: 332
Posts: 22817
Logic is my way
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

IMHO that should not be considered an error at all (I mean in the "C world"). I mean, it's legal even it's not logic. Who would have to know if an assignement has been done or not? In the other hand, who would have to do an assignement in an equality testing?
Why did they use two different symbols? I understand that there are historic considerations behinds, but I do not know them  smiley-wink
Personally, I began programming with BASIC, and used the "=" sign both the operations, and I disagreed the way C interpretes those operands.
Logged


0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 291
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In swift you can do
Code:
if var x = 1

or

Code:
if let x = 1 //let is const in C
and that would be legal. I'm not sure how declaring the variable in the if condition works but that's legal.

I guess declaring a variable in the condition would be an automatic true?
« Last Edit: July 06, 2014, 12:52:37 pm by mistergreen » Logged

0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 291
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh btw, the datatype on variables are assumed like

Code:
var x = 1
The compiler assumes x is an int since you assigned it an integer but you can you can manually do it too.

Code:
var x: Int = 1
« Last Edit: July 06, 2014, 02:12:24 pm by mistergreen » Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 70
Posts: 2176
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

In swift you can do
Code:
if var x = 1
I guess declaring a variable in the condition would be an automatic true?

Its no different to C++:

Code:
if( int x = 1 )

Dunno about swift, however, C++ will return false if 0 was assigned.

Quote
Oh btw, the datatype on variables are assumed

C++11 has the 'auto' data type.

I'll stick with my platform independent stuff for now.
Logged


0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 291
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Code:
if( int x = 1 )

Dunno about swift, however, C++ will return false if 0 was assigned.


In swift an int 1 and 0 can't  represent true and false respectively. Only Boolean values.
Logged

Pages: [1]   Go Up
Jump to: