• 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: Obj-c to Swift conversion question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Obj-c to Swift conversion question


  • Subject: Re: Obj-c to Swift conversion question
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Tue, 28 Jul 2015 17:34:57 +0200

> Le 28 juil. 2015 à 16:03, Eric E. Dolecki <email@hidden> a écrit :
>
> The more I stretch to Swift goals, the more I learn. However I've come upon
> a little thing where I am translating code into Swift and quickly stumbled.
>
> *Obj-C:*
> NSValue *keyboardEndFrameValue = [[notification userInfo]
> objectForKey:UIKeyboardFrameEndUserInfoKey];
>
>
> *Swift (the closest I've come):*
> var keyboardEndFrameValue =
> NSValue(notification.userInfo[UIKeyboardFrameEndUserInfoKey])
>

NSValue() is not a cast, it is a constructor.

Should be something like

var keyboardEndFrameValue = notification.userInfo[UIKeyboardFrameEndUserInfoKey] as NSValue


> Error for Swift: insert nonretainedObject:
> When I "Fix-It" with the above suggestion, the error becomes "Cannot
> subscript a value of type '[NSObject: AnyObject]?' with an index of type
> 'String'
>
> So I then end up with this (but it looks really strange):
>
> var keyboardEndFrameValue = NSValue(nonretainedObject:
> notification.userInfo[UIKeyboardFrameEndUserInfoKey as String])
>
> No warnings or errors, but I wanted to check to see if I'm appeasing the
> compiler but have it wrong.
>
> Thanks,
> Eric
> _______________________________________________
>
> 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


_______________________________________________

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


  • Follow-Ups:
    • Re: Obj-c to Swift conversion question
      • From: "Eric E. Dolecki" <email@hidden>
References: 
 >Obj-c to Swift conversion question (From: "Eric E. Dolecki" <email@hidden>)

  • Prev by Date: Obj-c to Swift conversion question
  • Next by Date: Re: Issues with WKWebView: "Requestor is not a platform binary"
  • Previous by thread: Obj-c to Swift conversion question
  • Next by thread: Re: Obj-c to Swift conversion question
  • Index(es):
    • Date
    • Thread