Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Device.swift usable from objc #224

Merged

Conversation

manuroe
Copy link
Contributor

@manuroe manuroe commented Jan 29, 2018

Hi,
This PR turns Device.swift into a class that can be usable from objc.
It also gives human readable names to latest iPhones.


// The native screen size
public let nativeScreenSize: CGSize?
@objc public let nativeScreenSize: CGSize
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You changed the nativeScreenSize to non-optional, but for macOS it is not defined. Correct me if I am wrong on that point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My issue was that optional non class parameter like CGSize? cannot be represented in objc. I got a build error when prefixing it with @objc.
As a Swift rookie, I decided to remove the optionality. Could you advice what is the best thing to do in that situation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see your issue there. Yeah. Only pointers to objects can be represented as optionals in Objective-C (null pointer then).

Since making this a pointer would be very weird I think there would be two solutions. Either define "no native screen size is defined" as CGSize.zero or as "is equivalent to screen size". I think the first would be better, since a screen size with no width or height could easily be understood as "not defined". Either way, please add a short comment in the documentation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely. Thanks!

case "iPhone10,3": return "iPhone X (GSM+CDMA)"
case "iPhone10,4": return "iPhone 8 (Global)"
case "iPhone10,5": return "iPhone 8 Plus (Global)"
case "iPhone10,6": return "iPhone X (Global)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Thanks!

@brototyp
Copy link
Member

If you merge develop in here I am fine to merge.

@manuroe
Copy link
Contributor Author

manuroe commented Jan 31, 2018

If you merge develop in here I am fine to merge.

@brototyp: done

@brototyp brototyp merged commit 0fbb40f into matomo-org:develop Feb 1, 2018
@brototyp
Copy link
Member

brototyp commented Feb 1, 2018

@manuroe Lovely, thanks! I will add a Changelog entry.

brototyp pushed a commit that referenced this pull request Feb 1, 2018
* Device.swift: make it a class usable from objc

* Device.swift: Add human readable platform names for iPhone 8, 8 Plus and X

* Device.swift: Make nativeScreenSize return CGSize.zero if the value is not defined on the running platform
brototyp pushed a commit that referenced this pull request Feb 26, 2018
* Device.swift: make it a class usable from objc

* Device.swift: Add human readable platform names for iPhone 8, 8 Plus and X

* Device.swift: Make nativeScreenSize return CGSize.zero if the value is not defined on the running platform
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants