Code Monkey home page Code Monkey logo

Comments (6)

 avatar commented on May 29, 2024

Our policy will be to prefer Swift's built-in types. In some cases, the functionality is not identical so there may be cases where one is preferred over the other, but in general, default to Swift types.

--------- Original Message --------- Subject: [swift-style-guide] Swift native types vs. ObjC native types (#15)
From: "Soheil Moayedi Azarpour" [email protected]
Date: 6/10/14 9:59 pm
To: "raywenderlich/swift-style-guide" [email protected]

Is there any preference to use native Swift type vs. ObjC type?
Not sure if there are any side effects or benefits, so I thought I would pose this as a new issue.
For example both of the following declarations are valid:
@objc class LoggedDate { let date: NSDate let formattedDateAsString: NSString init(date: NSDate, formattedDateAsString: NSString) { self.date = date self.formattedDateAsString = formattedDateAsString } } and
@objc class LoggedDate { let date: NSDate let formattedDateAsString: String init(date: NSDate, formattedDateAsString: String) { self.date = date self.formattedDateAsString = formattedDateAsString } } and formattedDateAsString can be assigned to an ObjC property that is NSString, e.g. cell.textLabel.text = loggedDate.formattedDateAsString in a Swift class.
We can extend this question to cover
Int vs. NSInteger or
Float vs. float and CGFloat, or
var arrayOfInt = [1, 2, 3] vs. var arrayOfInt = NSArray(objects: 1, 2, 3)

Reply to this email directly or view it on GitHub.

from swift-style-guide.

ColinEberhardt avatar ColinEberhardt commented on May 29, 2024

We should favour Swift types. Regarding your specific example ...

  • Swift does not have a date type (yet), so use NSDate for now.
  • The Swift String type is bridged to the NSString type, as a result it has all teh same API methods and can be used interchangeably.

from swift-style-guide.

jackwu95 avatar jackwu95 commented on May 29, 2024

+1 for always favor Swift types when available.

Its annoying at times when you have to do myFloatString.bridgeToObjectiveC().floatValue() because Swift's String type doesn't support it.

from swift-style-guide.

ColinEberhardt avatar ColinEberhardt commented on May 29, 2024

I have a feeling this is a short term problem and we will see the 'native' Swift API grow. I bet we will see a Date type soon.

from swift-style-guide.

icanzilb avatar icanzilb commented on May 29, 2024

Agreed ... At least data types should be more or less fixed in the next
betas

On Thursday, June 12, 2014, ColinEberhardt [email protected] wrote:

I have a feeling this is a short term problem and we will see the 'native'
Swift API grow. I bet we will see a Date type soon.


Reply to this email directly or view it on GitHub
#15 (comment)
.

from swift-style-guide.

rwenderlich avatar rwenderlich commented on May 29, 2024

What about in Sprite Kit - CGFloat vs. Double? Prefer using Double except when you must convert to CGFloat?

from swift-style-guide.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.