Re: Need for Swift

2019-10-16 Thread Charles Srstka via Cocoa-dev
> On Oct 16, 2019, at 2:38 PM, Jean-Daniel via Cocoa-dev 
>  wrote:
> 
>> Le 16 oct. 2019 à 11:49, Stephane Sudre via Cocoa-dev 
>> mailto:cocoa-dev@lists.apple.com>> a écrit :
>> 
>> On Tue, Oct 15, 2019 at 2:26 PM Sandor Szatmari via Cocoa-dev
>> mailto:cocoa-dev@lists.apple.com>> wrote:
>> 
>>> But honestly, I don’t have enough Swift experience to know if you can write 
>>> bad Swift code.
>> 
>> I'm just reading Swift code here and there and it's my personal
>> opinion that 75% of the Swift code I read is bad code.
> 
> That matches my observation whatever the language is. 
> This is not something related to Swift. This is just how most developers 
> works.

+1

>> Why do Swift developers think it's mandatory to write code that is illegible?
>> Is Swift mainly used by freelances or consultants that will not have
>> to maintain the software?
> 
> Not more than other projects with language designed to be easy to use and 
> usable by as many people as possible.
> 
> You won’t find as much bad C++ and Rust code because the complexity of the 
> languages filter out casual developers.

And it’s certainly not as if there’s not a lot of terrible Objective-C code out 
there.

Charles

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Alerts in Xcode 11

2019-10-16 Thread Alex Zavatone via Cocoa-dev
Yeah, one thing you need to do is get the key window’s presentedViewController. 
 You can do this from the shared applicationDelegate.  Create a standalone 
class that gets UIApplication.shared().keywindow.presentedViewController.  
Think of that as self.  And then use that to present the alert.  Add a weak 
reference back to whichever object you need to do stuff when buttons are 
pressed in that alert.

Hope this helps.

> On Oct 16, 2019, at 6:00 PM, Doug Hardie via Cocoa-dev 
>  wrote:
> 
> I finally got some time to get back to this again.  The extension does a lot 
> of what I need.  It works great if it is called from any UIViewController.  
> However, if I call it from a function that is not in a view controller then 
> Swift says notificationAlert is not defined.  There is another side effect 
> that is more problematic, When the alert is displayed, I also get the message:
> 
> popViewControllerAnimated: called on  
> while an existing transition or presentation is occurring; the navigation 
> stack will not be updated.
> 
> Generally these alerts are used when a user tries to enter a view controller 
> where the prerequisite data has not been provided.  I wanted the alert to 
> display and then go back to the previous view controller.  I suspect that I 
> will need to use completions in the notificationAlert function to do that 
> rather than just following the call with the stack pop.
> 
> -- Doug
> 
>> On 9 October 2019, at 07:40, davel...@mac.com wrote:
>> 
>> I'm by no means an expert but if I understand what you're trying to do, I 
>> think the approach I would take is to make an extension on UIViewController:
>> 
>> extension UIViewController {
>>   func notificationAlert(_ msg1: String, _ msg2: String) {
>> 
>>   // create the UIAlertAlertController
>>   // and then do as David Duncan said and do:
>>   self.present(, animated:  completion: …)
>>   }
>> }
>> 
>> Now all your UIViewController subclasses can call that method (and because 
>> it's a method, they have access to self which is a subclass of 
>> UIViewController).
>> 
>> HTH,
>> Dave
>> 
>> 
>>> On Sep 30, 2019, at 11:27 PM, Doug Hardie via Cocoa-dev 
>>>  wrote:
>>> 
>>> I tried that and swift complains that self is not defined.  This is not in 
>>> a view controller but a stand alone function used in many view controllers. 
>>>  Generally it is used during a segue, but I added one in a view controller 
>>> to a button action, not part of a segue and it dismissed the alert also.  
>>> 
>>> -- Doug
>>> 
 On 30 September 2019, at 19:48, David Duncan  
 wrote:
 
 Instead of creating a new window and a root view controller in order to 
 present your alert, just use (assuming self is a UIViewController) 
 self.present(, animated:  completion: …)
 
> On Sep 30, 2019, at 5:48 PM, Doug Hardie  wrote:
> 
> Not sure how to do that.  It's not in any view controller as it is used 
> in virtually all of the various view controllers.  That's why I wanted it 
> as a function.
> 
> -- Doug
> 
>> On 30 September 2019, at 14:44, David Duncan  
>> wrote:
>> 
>> What happens if you present it over your normal view controller 
>> hierarchy instead of using another window?
>> 
>> Has your application adopted UIWindowScene?
>> 
>>> On Sep 30, 2019, at 5:36 PM, Doug Hardie via Cocoa-dev 
>>>  wrote:
>>> 
>>> I have some code that presents an alert to the user with information 
>>> they need, and an OK button to clear it.  It works fine in the previous 
>>> Xcode versions.  However, after upgrading to 11, it now displays the 
>>> alert and then immediately clears it.  This happens both in the 
>>> simulator and on a real device.  I have played around with the code and 
>>> can't figure out how to make it leave the alert on the screen.  This is 
>>> in Swift.  It is a function that is called from numerous places in the 
>>> app.
>>> 
>>> func NotificationAlert (_ msg1: String, _ msg2: String) {
>>> let ErrorAlert = UIAlertController(title: msg1, message: msg2, 
>>> preferredStyle: .alert)
>>> let dismiss = UIAlertAction(title: "Ok", style: .default, handler: nil)
>>> ErrorAlert.addAction(dismiss)
>>> ErrorAlert.presentInOwnWindow(animated: true, completion: nil)
>>> }
>>> 
>>> extension UIAlertController {
>>> func presentInOwnWindow(animated: Bool, completion: (() -> Void)?) {
>>>  let alertWindow = UIWindow(frame: UIScreen.main.bounds)
>>>  alertWindow.rootViewController = UIViewController()
>>>  alertWindow.windowLevel = UIWindow.Level.alert + 1;
>>>  alertWindow.makeKeyAndVisible()
>>>  alertWindow.rootViewController?.present(self, animated: animated, 
>>> completion: completion)
>>> }
>>> }
>>> 
>>> 
>>> -- Doug
>>> 
>>> ___
>>> 
>>> Cocoa-dev mailing list 

Re: Alerts in Xcode 11

2019-10-16 Thread Doug Hardie via Cocoa-dev
I finally got some time to get back to this again.  The extension does a lot of 
what I need.  It works great if it is called from any UIViewController.  
However, if I call it from a function that is not in a view controller then 
Swift says notificationAlert is not defined.  There is another side effect that 
is more problematic, When the alert is displayed, I also get the message:

popViewControllerAnimated: called on  
while an existing transition or presentation is occurring; the navigation stack 
will not be updated.

Generally these alerts are used when a user tries to enter a view controller 
where the prerequisite data has not been provided.  I wanted the alert to 
display and then go back to the previous view controller.  I suspect that I 
will need to use completions in the notificationAlert function to do that 
rather than just following the call with the stack pop.

-- Doug

> On 9 October 2019, at 07:40, davel...@mac.com wrote:
> 
> I'm by no means an expert but if I understand what you're trying to do, I 
> think the approach I would take is to make an extension on UIViewController:
> 
> extension UIViewController {
>func notificationAlert(_ msg1: String, _ msg2: String) {
> 
>// create the UIAlertAlertController
>// and then do as David Duncan said and do:
>self.present(, animated:  completion: …)
>}
> }
> 
> Now all your UIViewController subclasses can call that method (and because 
> it's a method, they have access to self which is a subclass of 
> UIViewController).
> 
> HTH,
> Dave
> 
> 
>> On Sep 30, 2019, at 11:27 PM, Doug Hardie via Cocoa-dev 
>>  wrote:
>> 
>> I tried that and swift complains that self is not defined.  This is not in a 
>> view controller but a stand alone function used in many view controllers.  
>> Generally it is used during a segue, but I added one in a view controller to 
>> a button action, not part of a segue and it dismissed the alert also.  
>> 
>> -- Doug
>> 
>>> On 30 September 2019, at 19:48, David Duncan  wrote:
>>> 
>>> Instead of creating a new window and a root view controller in order to 
>>> present your alert, just use (assuming self is a UIViewController) 
>>> self.present(, animated:  completion: …)
>>> 
 On Sep 30, 2019, at 5:48 PM, Doug Hardie  wrote:
 
 Not sure how to do that.  It's not in any view controller as it is used in 
 virtually all of the various view controllers.  That's why I wanted it as 
 a function.
 
 -- Doug
 
> On 30 September 2019, at 14:44, David Duncan  
> wrote:
> 
> What happens if you present it over your normal view controller hierarchy 
> instead of using another window?
> 
> Has your application adopted UIWindowScene?
> 
>> On Sep 30, 2019, at 5:36 PM, Doug Hardie via Cocoa-dev 
>>  wrote:
>> 
>> I have some code that presents an alert to the user with information 
>> they need, and an OK button to clear it.  It works fine in the previous 
>> Xcode versions.  However, after upgrading to 11, it now displays the 
>> alert and then immediately clears it.  This happens both in the 
>> simulator and on a real device.  I have played around with the code and 
>> can't figure out how to make it leave the alert on the screen.  This is 
>> in Swift.  It is a function that is called from numerous places in the 
>> app.
>> 
>> func NotificationAlert (_ msg1: String, _ msg2: String) {
>> let ErrorAlert = UIAlertController(title: msg1, message: msg2, 
>> preferredStyle: .alert)
>> let dismiss = UIAlertAction(title: "Ok", style: .default, handler: nil)
>> ErrorAlert.addAction(dismiss)
>> ErrorAlert.presentInOwnWindow(animated: true, completion: nil)
>> }
>> 
>> extension UIAlertController {
>> func presentInOwnWindow(animated: Bool, completion: (() -> Void)?) {
>>   let alertWindow = UIWindow(frame: UIScreen.main.bounds)
>>   alertWindow.rootViewController = UIViewController()
>>   alertWindow.windowLevel = UIWindow.Level.alert + 1;
>>   alertWindow.makeKeyAndVisible()
>>   alertWindow.rootViewController?.present(self, animated: animated, 
>> completion: completion)
>> }
>> }
>> 
>> 
>> -- Doug
>> 
>> ___
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> 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:
>> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
>> 
>> This email sent to david.dun...@apple.com
> 
 
>>> 
>> 
>> ___
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at 

Re: Need for Swift

2019-10-16 Thread Jean-Daniel via Cocoa-dev


> Le 16 oct. 2019 à 11:49, Stephane Sudre via Cocoa-dev 
>  a écrit :
> 
> On Tue, Oct 15, 2019 at 2:26 PM Sandor Szatmari via Cocoa-dev
>  wrote:
> 
>> But honestly, I don’t have enough Swift experience to know if you can write 
>> bad Swift code.
> 
> I'm just reading Swift code here and there and it's my personal
> opinion that 75% of the Swift code I read is bad code.

That matches my observation whatever the language is. 
This is not something related to Swift. This is just how most developers works.

> Why do Swift developers think it's mandatory to write code that is illegible?
> Is Swift mainly used by freelances or consultants that will not have
> to maintain the software?

Not more than other projects with language designed to be easy to use and 
usable by as many people as possible.

You won’t find as much bad C++ and Rust code because the complexity of the 
languages filter out casual developers.





___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Need for Swift

2019-10-16 Thread Alex Zavatone via Cocoa-dev


> On Oct 16, 2019, at 4:49 AM, Stephane Sudre via Cocoa-dev 
>  wrote:
> 
> Why do Swift developers think it's mandatory to write code that is illegible?
> Is Swift mainly used by freelances or consultants that will not have
> to maintain the software?

The zest to do things in a way, “because it is Swifty”.  

That doesn’t mean that it is good.  And people insist that “because it is 
Swifty”, it must be the new best thing and clearly everyone else “just doesn’t 
understand the new way”.

It’s pretty arrogant, but that’s what I’ve seen as well.  People need to 
evaluate a new approach and based upon their experience, decide if it is a good 
thing.  Honestly, our developers want to rush to SwiftUI and embrace everything 
new without realizing that we still need to support users running iOS 10.  

Anyway, It’s an enthusiastic jump to adopt the new without considering what 
about it is wise to do.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Need for Swift

2019-10-16 Thread Stephane Sudre via Cocoa-dev
On Tue, Oct 15, 2019 at 2:26 PM Sandor Szatmari via Cocoa-dev
 wrote:

> But honestly, I don’t have enough Swift experience to know if you can write 
> bad Swift code.

I'm just reading Swift code here and there and it's my personal
opinion that 75% of the Swift code I read is bad code.

By bad code, I mean code suffering from the "only God and I know what
I'm doing" syndrome.

The same syndrome that you can find in software using Cocoa bindings.
The same software that is terrible to maintain, even more when you're
not the original author (and you're obviously not God).

Why do Swift developers think it's mandatory to write code that is illegible?
Is Swift mainly used by freelances or consultants that will not have
to maintain the software?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com