• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: UIKit and Swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: UIKit and Swift


  • Subject: Re: UIKit and Swift
  • From: Roland King <email@hidden>
  • Date: Mon, 16 Jun 2014 07:08:00 +0800

>
> Ah ok, figured it out; your code gave me a hint. If you have a String, the methods that are in NSString just work on it. If you want the extensions, you have to be explicit about NSString:
>
> drawable.name is a String?:
>
>
> 		// does not work, sizeWithFont not found
>                 if let name = drawable.name {
>                     var size = name.sizeWithFont(font)
> 		    // etc...
>                 }
>
> 		// works fine
>                 if let name: NSString = drawable.name {
>                     var size = name.sizeWithFont(font)
> 		    // etc...
>                 }
>
> (Yes, sizeWithFont is deprecated, I still need to switch it out with sizeWithAttributes)
>
> Thanks!!
>

I finally came across this in the 'Swift Interoperability in Depth" WWDC video where it says ..

	Foundation NSString APIs are available on String


		let fruits = "apple;banana;cherry".componentsSeparatedByString(";")
		// inferred as String[]

	Cast to NSString to access properties and methods on NSString categories


		("Welcome to WWDC 2014" as NSString).myNSStringMethod()


it also suggests that if you find yourself doing that often for a given method, you write the extension in Swift.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >UIKit and Swift (From: Jim Geist <email@hidden>)
 >Re: UIKit and Swift (From: Kyle Sluder <email@hidden>)
 >Re: UIKit and Swift (From: Roland King <email@hidden>)
 >Re: UIKit and Swift (From: Jim Geist <email@hidden>)

  • Prev by Date: Re: title bar hit test?
  • Next by Date: CGDisplayIOServicePort deprecated in 10.9... IOServicePortFromCGDisplayID?
  • Previous by thread: Re: UIKit and Swift
  • Next by thread: UITableView's tableFooterView and autolayout
  • Index(es):
    • Date
    • Thread