Date   

Re: Scanner oddity

Sandor Szatmari
 

Laurent,

On Sep 29, 2021, at 15:11, Laurent Daudelin <laurent@...> wrote:

Anybody uses the Scanner class?

I’m using an instance to extract some data from a string received from a web server.

If I have a string that is “45\nBlah”, read the “45”, the

Have you tried -setCharactersToBeSkipped:

Set that to skip new line, carriage return… 

Maybe that will work for you?

Sandor

scanner location is just before the carriage return. If I then try a someString = scanner.scanString(“\nBlah”), someString is nil. But if I do scanner.scanLocation += 1, then someString = scanner.scanString(“Blah”), then someString contains “Blah”. Not sure if I’m using it correctly or if there is some kind of a bug.

By the way, speaking of “scanLocation”, the editor gives me a warning that it’s been deprecated as of iOS 13. But when I open the documentation about the Scanner, there is no mention that it’s been deprecated. Further, the editor doesn’t suggest a replacement.

What am I missing?

-Laurent.
-- 
Laurent Daudelin   laurent@...
Skype: LaurentDaudelin
Logiciels Némésys Software   http://www.nemesys-soft.com/


Scanner oddity

Laurent Daudelin
 

Anybody uses the Scanner class?

I’m using an instance to extract some data from a string received from a web server.

If I have a string that is “45\nBlah”, read the “45”, the scanner location is just before the carriage return. If I then try a someString = scanner.scanString(“\nBlah”), someString is nil. But if I do scanner.scanLocation += 1, then someString = scanner.scanString(“Blah”), then someString contains “Blah”. Not sure if I’m using it correctly or if there is some kind of a bug.

By the way, speaking of “scanLocation”, the editor gives me a warning that it’s been deprecated as of iOS 13. But when I open the documentation about the Scanner, there is no mention that it’s been deprecated. Further, the editor doesn’t suggest a replacement.

What am I missing?

-Laurent.
-- 
Laurent Daudelin   laurent@...
Skype: LaurentDaudelin
Logiciels Némésys Software   http://www.nemesys-soft.com/


How to embed Swift Package executable into macOS app

Jim
 

I have a macOS app I’d like to embed an executable from a swift package. However, while I can add the swift package under the app target’s “Frameworks, Libraries, and Embedded Content” section, and add it to Dependencies in Build Phases, it doesn’t show up as a project resource in the “Copy Bundle Resources” section. Is there some step I’m missing?

Also, I had accidentally dragged the executable to my project and added that in the “Copy Bundle Resources” section, but when I tried to notarize it refused because the executable wasn’t built with hardened runtime. Is it possible to build a command-line executable from a Swift package with hardened runtime?

This is all pointing me back to how I had first added this, with a separate target and scheme in the main project for the command line tool. However, that also added the command line tool as a product, and even though I turned off “Archive” in the scheme for the command line tool it was still archived as a separate product. This archived as a folder with both products and I wasn’t able to use Xcode’s built-in notarization process. I can notarize outside of Xcode if I have to but it doesn’t seem like this should be so difficult. Also I’d prefer to have the command line tool in its own project if possible.

Jim Crate


Re: Async/Await and Model Dialogs

David M. Cotter
 

also you can enlargen your screen resolution:

apple->system prefs->displays->display
resolution: scaled, click "more space" on the far right

-dave

On Sep 21, 2021, at 2:27 PM, Rick Aurbach via groups.io <rlaurb@...> wrote:

In a UIKit context, has anyone had experience/success in using async/await to synchronize a modal dialog with other logic? I've tried it a bit without success.

I.e, given a presented dialog, I want to capture data in the dialog, then use the results in a simple, linear fashion. (Something that looks like "Present the dialog, wait for results, use results" -- all inline.) It seems to me that async/await with @MainActor ought to make that possible, but  I haven't yet figured out how. I'd really like to see a real-world example.

Can you help?


Async/Await and Model Dialogs

Rick Aurbach
 

In a UIKit context, has anyone had experience/success in using async/await to synchronize a modal dialog with other logic? I've tried it a bit without success.

I.e, given a presented dialog, I want to capture data in the dialog, then use the results in a simple, linear fashion. (Something that looks like "Present the dialog, wait for results, use results" -- all inline.) It seems to me that async/await with @MainActor ought to make that possible, but  I haven't yet figured out how. I'd really like to see a real-world example.

Can you help?


Re: Just a little sharing - it's nice when your product finally hits the market.

Alex Zavatone
 

I don’t know. I was at MorphoTrust in 2014 when we worked on what would become the Apple Drivers’ Licence app. I did the first iOS working prototype with Dan, Ted and Clayton. Our PM was Steve Miu. Since then, MorphoTrust has gone through a few corporate hands. It was even owned by a French company for a while. Not sure who owns it now. It took forever to get the product picked up from what I know. Would have loved to be still working on it!

Cheers!
Alex Zavatone

On Sep 1, 2021, at 3:14 PM, Jack Brindle via groups.io <jackbrindle=me.com@groups.io> wrote:

Louisiana has had a driver’s license app for several years. Is that your work, Alex?

Jack

On Sep 1, 2021, at 2:32 PM, Alex Zavatone via groups.io <zav=mac.com@groups.io> wrote:

My olden app has finally hit the market.

https://www.macrumors.com/2021/09/01/apple-shares-us-states-adopting-wallet-ids/

It’s only taken 7 years since I worked on it. : )

Cheers to everyone else who was able to bring it to market.

Best,
Alex Zavatone








Re: Just a little sharing - it's nice when your product finally hits the market.

Jack Brindle
 

Louisiana has had a driver’s license app for several years. Is that your work, Alex?

Jack

On Sep 1, 2021, at 2:32 PM, Alex Zavatone via groups.io <zav=mac.com@groups.io> wrote:

My olden app has finally hit the market.

https://www.macrumors.com/2021/09/01/apple-shares-us-states-adopting-wallet-ids/

It’s only taken 7 years since I worked on it. : )

Cheers to everyone else who was able to bring it to market.

Best,
Alex Zavatone




Just a little sharing - it's nice when your product finally hits the market.

Alex Zavatone
 

My olden app has finally hit the market.

https://www.macrumors.com/2021/09/01/apple-shares-us-states-adopting-wallet-ids/

It’s only taken 7 years since I worked on it. : )

Cheers to everyone else who was able to bring it to market.

Best,
Alex Zavatone


WKWebKit and iOS 13 in Xcode 12

Alex Zavatone
 

Has anyone found a workaround for the crash of WKWebKit under the above configuration?  Xcode reposts “Error acquiring assertion” trying to display any webpage.

A workaround to prevent the screen from blanking out is this, but it doesn’t stop WKWebKit from crashing.

    override func willMove(toParent: UIViewController? ) {
        print("Something")
    }

Basically, loading any webpage crashes out in WebKit, iOS 13 and Xcode 12.  It’s fine in iOS 14.

Thanks in advance.
Alex Zavatone


Re: New syntax in Xcode 12.5.

Alex Zavatone
 

I found out what the issue was.  The programmer didn’t add a self in front of variables that had the same name as the local that he was creating.   Xcode 12.4 reports an error until you add self in front of the properties.  Xcode 12.5 can handle 

The actual line looked more like this.

let myVar = myVar != someValue ? myVar : myOtherAssignment

It actually should be    

let myVar = self.myVar != someValue ? self.myVar : myOtherAssignment

Thanks.
Alex Zavatone

On Jul 26, 2021, at 11:19 AM, Jeremy Hughes via groups.io <moon.rabbit@...> wrote:

1. myVar != someValue is the condition.

2. It determines whether the ternary expression evaluates to resultOne or resultTwo

3. resultOne or resultTwo is what is assigned in let myVar =

This seems like a standard use of the ternary conditional operator. I don’t have any problems compiling it in Xcode 12.4.

Jeremy



On 26 Jul 2021, at 16:57, Alex Zavatone via groups.io <zav@...> wrote:

The first half.  Ternary has been there since time began.  I’ve never seen this part be legitimate before.

let myVar = myVar != someValue



On Jul 26, 2021, at 10:09 AM, Jeremy Hughes via groups.io <moon.rabbit@...> wrote:

Are you referring to the ternary conditional operator, which has existed in Swift since the beginning, or to the fact that it creates a local variable with the same name (myVar) as a parameter or member (myVar)?

Jeremy



On 26 Jul 2021, at 15:37, Alex Zavatone via groups.io <zav@...> wrote:

I just saw someone use this syntax in a project and haven’t see it before.  It compiles in Xcode 12.5, but not in Xcode 12.4.  Does anyone have any more details on it?

let myVar = myVar != someValue ? resultOne : resultTwo

Swift sure is getting muddier and muddier with regards to visual comprehension.

Thanks in advance.
Alex Zavatone



















Re: New syntax in Xcode 12.5.

Jeremy Hughes
 

1. myVar != someValue is the condition.

2. It determines whether the ternary expression evaluates to resultOne or resultTwo

3. resultOne or resultTwo is what is assigned in let myVar =

This seems like a standard use of the ternary conditional operator. I don’t have any problems compiling it in Xcode 12.4.

Jeremy

On 26 Jul 2021, at 16:57, Alex Zavatone via groups.io <zav=mac.com@groups.io> wrote:

The first half. Ternary has been there since time began. I’ve never seen this part be legitimate before.

let myVar = myVar != someValue


On Jul 26, 2021, at 10:09 AM, Jeremy Hughes via groups.io <moon.rabbit=virginmedia.com@groups.io> wrote:

Are you referring to the ternary conditional operator, which has existed in Swift since the beginning, or to the fact that it creates a local variable with the same name (myVar) as a parameter or member (myVar)?

Jeremy



On 26 Jul 2021, at 15:37, Alex Zavatone via groups.io <zav=mac.com@groups.io> wrote:

I just saw someone use this syntax in a project and haven’t see it before. It compiles in Xcode 12.5, but not in Xcode 12.4. Does anyone have any more details on it?

let myVar = myVar != someValue ? resultOne : resultTwo

Swift sure is getting muddier and muddier with regards to visual comprehension.

Thanks in advance.
Alex Zavatone







Re: New syntax in Xcode 12.5.

Alex Zavatone
 

The first half. Ternary has been there since time began. I’ve never seen this part be legitimate before.

let myVar = myVar != someValue


On Jul 26, 2021, at 10:09 AM, Jeremy Hughes via groups.io <moon.rabbit=virginmedia.com@groups.io> wrote:

Are you referring to the ternary conditional operator, which has existed in Swift since the beginning, or to the fact that it creates a local variable with the same name (myVar) as a parameter or member (myVar)?

Jeremy



On 26 Jul 2021, at 15:37, Alex Zavatone via groups.io <zav=mac.com@groups.io> wrote:

I just saw someone use this syntax in a project and haven’t see it before. It compiles in Xcode 12.5, but not in Xcode 12.4. Does anyone have any more details on it?

let myVar = myVar != someValue ? resultOne : resultTwo

Swift sure is getting muddier and muddier with regards to visual comprehension.

Thanks in advance.
Alex Zavatone





Re: New syntax in Xcode 12.5.

Jeremy Hughes
 

Are you referring to the ternary conditional operator, which has existed in Swift since the beginning, or to the fact that it creates a local variable with the same name (myVar) as a parameter or member (myVar)?

Jeremy

On 26 Jul 2021, at 15:37, Alex Zavatone via groups.io <zav=mac.com@groups.io> wrote:

I just saw someone use this syntax in a project and haven’t see it before. It compiles in Xcode 12.5, but not in Xcode 12.4. Does anyone have any more details on it?

let myVar = myVar != someValue ? resultOne : resultTwo

Swift sure is getting muddier and muddier with regards to visual comprehension.

Thanks in advance.
Alex Zavatone


New syntax in Xcode 12.5.

Alex Zavatone
 

I just saw someone use this syntax in a project and haven’t see it before.  It compiles in Xcode 12.5, but not in Xcode 12.4.  Does anyone have any more details on it?

let myVar = myVar != someValue ? resultOne : resultTwo

Swift sure is getting muddier and muddier with regards to visual comprehension.

Thanks in advance.  
Alex Zavatone


Re: Help with iOS 15-style UIButton?

Rick Aurbach
 

Just to finish up this discussion, below is the code I ended up with for my button that is compatible with both pre-15 and post-15 code.

I think that if you subclass UIButton in your current code, (particularly if you use titleEdgeInsets and/or imageEdgeInsets, you need to test for breaking changes in iOS15.

Good luck to all.


Re: CGContext always creating a black rect.

Ben Kennedy
 

On 24 Jul 2021, at 12:56 pm, Alex Zavatone via groups.io <zav=mac.com@groups.io> wrote:

I know I don’t need the self, but I want the context. A variable just sitting around tells me nothing about the context in which it exists. I want to see the context and want to see the self.
I initially felt that way too, several years ago, when first coming from Obj-C. However, I learned to embrace the tools (which make it easy to find the declaration) and also be mindful of writing clear and well-organized code to keep the mental burden of symbol bookkeeping to a minimum.

Moreover, following conventional style (which, in Swift, eschews the redundant `self.`) makes it easier to work with other developers.

- That same function seems like it ought to be pure; i.e., have no side effects -- just draw a rect based on its argument. However, it does math and sets instance variables. If it needs to affect and act on persistent state, it ought to be refactored.
Refactored how? [...]

Here’s how I currently call it. [...]

self.roundedRect.configure(rectWidth: rectWidth, rectHeight: rectHeight, rectBgColor: rectBgColor , rectBorderColor: rectBorderColor, rectBorderWidth: rectBorderWidth, rectCornerRadius: rectCornerRadius)

self.view.addSubview(roundedRect)
Seems like your `configure(…)` method is the ideal place for those calculations.

In Swift, I HATE how they have done method parameters, so I’m opting for redundant redundancy over terseness or brevity.
I'm not sure what you're referring to about "how they have done method parameters".

-ben


Re: CGContext always creating a black rect.

Alex Zavatone
 

Thanks.

I know I don’t need the self, but I want the context.  A variable just sitting around tells me nothing about the context in which it exists.  I want to see the context and want to see the self.

- The `roundRect(…)` function would be better named as `drawRoundRect(…)`.

Good point.

On Jul 24, 2021, at 2:32 PM, Ben Kennedy <ben-groups@...> wrote:

On 24 Jul 2021, at 11:37 am, Alex Zavatone via groups.io <zav@...> wrote:

Hi.  I’m trying to draw a bezier shape in CGContext on a UIView in Swift with a transparent background and the background is always black.  Nothing online helps.

Any ideas?  I’ve checked .isOpaque, backgroundColor.   Nothing I can do to get rid of the black rect background.  Any ideas?

Move your `backgroundColor` and `isOpaque` calls to the init method(s). I set up a test project with your code, and that solves the problem.

I was going to make that suggestion before I even tested it, though, because it's an obvious smell to me: there's no need to repeatedly set those properties every time you draw, but rather just once, at setup.

A couple of other code style comments:

- You don't need all the `self.` prefixes.

Want them.  They indicate scope.  I don’t need to think.  I just look at it and know the scope.  Anything that makes code more vague sucks.  I want easier understanding rather than “but we can use less words!”  People’s time is $$.

- The `roundRect(…)` function would be better named as `drawRoundRect(…)`.

- That same function seems like it ought to be pure; i.e., have no side effects -- just draw a rect based on its argument. However, it does math and sets instance variables. If it needs to affect and act on persistent state, it ought to be refactored.

Refactored how?

It can’t exist without its configuration being set and it will be drawing with those internal settings once I have the details set up.  Then it’s possible that I’ll move the configuration internal.  Eventually, it will have a gradient interior.  It’s replacing a UISwitch.

Here’s how I currently call it.

        self.roundedRect = RoundedRectUIView()
        self.roundedRect.backgroundColor = .clear
        self.roundedRect.clipsToBounds = true
        let rectBorderWidth = CGFloat(2)
        let rectWidth = CGFloat(100)
        let rectHeight = CGFloat(40)
        let rectBorderColor = UIColor.blue
        let rectBgColor = UIColor.systemGray3
        let rectCornerRadius = CGFloat(-1)
        let origin = CGPoint(x: 10, y: 200)
        viewRect = CGRect(origin: origin,
                          size: CGSize(width: rectWidth + rectBorderWidth * 2.0,
                                       height: rectHeight + (rectBorderWidth * 2.0)))
        self.roundedRect.frame = viewRect

                          

        self.roundedRect.configure(rectWidth: rectWidth, rectHeight: rectHeight, rectBgColor: rectBgColor , rectBorderColor: rectBorderColor, rectBorderWidth: rectBorderWidth, rectCornerRadius: rectCornerRadius)

        self.view.addSubview(roundedRect)

In Swift, I HATE how they have done method parameters, so I’m opting for redundant redundancy over terseness or brevity.

Thanks, Ben.
-ben








Re: CGContext always creating a black rect.

Ben Kennedy
 

On 24 Jul 2021, at 11:37 am, Alex Zavatone via groups.io <zav=mac.com@groups.io> wrote:

Hi. I’m trying to draw a bezier shape in CGContext on a UIView in Swift with a transparent background and the background is always black. Nothing online helps.

Any ideas? I’ve checked .isOpaque, backgroundColor. Nothing I can do to get rid of the black rect background. Any ideas?
Move your `backgroundColor` and `isOpaque` calls to the init method(s). I set up a test project with your code, and that solves the problem.

I was going to make that suggestion before I even tested it, though, because it's an obvious smell to me: there's no need to repeatedly set those properties every time you draw, but rather just once, at setup.

A couple of other code style comments:

- You don't need all the `self.` prefixes.

- The `roundRect(…)` function would be better named as `drawRoundRect(…)`.

- That same function seems like it ought to be pure; i.e., have no side effects -- just draw a rect based on its argument. However, it does math and sets instance variables. If it needs to affect and act on persistent state, it ought to be refactored.

-ben


CGContext always creating a black rect.

Alex Zavatone
 

Hi.  I’m trying to draw a bezier shape in CGContext on a UIView in Swift with a transparent background and the background is always black.  Nothing online helps.

Any ideas?  I’ve checked .isOpaque, backgroundColor.   Nothing I can do to get rid of the black rect background.  Any ideas?  

Thanks in advance.


    override func draw(_ rect: CGRect)
    {
        self.backgroundColor = .clear
        self.isOpaque = false
        super.draw(rect)
        roundRect(rect)
    }

    

    internal func roundRect(_ rect: CGRect)
    {
        self.backgroundColor = UIColor.clear

        

        // Make a pill shape if rectCornerRadius < 0
        let xHalf = self.frame.width / 2
        let yHalf = self.frame.height / 2

        

        if (self.rectCornerRadius < 0) {
            if (self.rectWidth <= self.rectHeight) {
            self.rectCornerRadius = (yHalf / 2)
            } else if (self.rectHeight <= self.rectWidth) {
                self.rectCornerRadius = (xHalf / 2)
            }
        }

        

        let ctx: CGContext = UIGraphicsGetCurrentContext()!

        ctx.clear(rect)
        ctx.saveGState()

        

        ctx.setLineWidth(rectBorderWidth)
        ctx.setStrokeColor(rectBorderColor.cgColor)

        

        let rect = CGRect(x: 0, y: 0, width: self.rectWidth, height: self.rectHeight)

        let clipPath: CGPath = UIBezierPath(roundedRect: rect, cornerRadius: self.rectCornerRadius).cgPath
        let linePath: CGPath = UIBezierPath(roundedRect: rect, cornerRadius: self.rectCornerRadius).cgPath

        

        ctx.addPath(clipPath)

        

        ctx.setFillColor(self.rectBgColor.cgColor)
        ctx.closePath()
        ctx.fillPath()

        

        ctx.addPath(linePath)
        ctx.strokePath()

        

        ctx.restoreGState()
    }


Re: Help with iOS 15-style UIButton?

Rick Aurbach
 
Edited

Hi, Alex.

The work-around was to force the button width to be "expectedWidth" (which is the width of the [unwrapped] text + image padding + image width + 8 points of slop (to account for button margins). If you notice, I override draw() to always make this adjustment just before calling super.draw(). The 8 its of margin was determined by experiment.

The comment about "mirroring above bounds code" just means that I was (historically) using different logic to adjust button size in the pre-15 case, and that I should probably change that code to use the same logic as the 15+ version.

Hope this helps.

1 - 20 of 1425