From 7f3052061319daeb129ceb5ebfaa1f763838a8eb Mon Sep 17 00:00:00 2001 From: Gilles Grousset Date: Mon, 29 Apr 2024 16:29:22 +0200 Subject: [PATCH 1/4] Added Swift version of EC512 --- .../src/main/rules/EC512/swift/EC512.asciidoc | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 ecocode-rules-specifications/src/main/rules/EC512/swift/EC512.asciidoc diff --git a/ecocode-rules-specifications/src/main/rules/EC512/swift/EC512.asciidoc b/ecocode-rules-specifications/src/main/rules/EC512/swift/EC512.asciidoc new file mode 100644 index 000000000..f1307fd72 --- /dev/null +++ b/ecocode-rules-specifications/src/main/rules/EC512/swift/EC512.asciidoc @@ -0,0 +1,44 @@ +Most iOS devices come equipped with a variety of sensors that measure motion, orientation, and various environmental conditions. +Additionally, these devices include advanced sensors such as the image sensor (commonly referred to as the Camera) and the geo-positioning sensor (commonly referred to as GPS). + +The common point of all these sensors is that they are power-intensive while in use. A typical issue arises when these sensors continue to process data unnecessarily after the application enters an idle state, like when it is backgrounded or the user stops interacting with it. + + As a result, calls to manage these sensors must be carefully paired: `AVCaptureSession.startRunning()` and `AVCaptureSession.stopRunning()`. + Failure to properly manage these calls can lead to significant battery drain within a few hours. + +== Noncompliant Code Example + +[source,swift] +---- +import AVFoundation + +class CameraManager { + var captureSession: AVCaptureSession? + + func activateCamera() { + captureSession = AVCaptureSession() + captureSession?.startRunning() // Camera starts capturing + // Missing corresponding stopRunning + } +} +---- + +== Compliant Code Example + +[source,swift] +---- +import AVFoundation + +class CameraManager { + var captureSession: AVCaptureSession? + + func activateCamera() { + captureSession = AVCaptureSession() + captureSession?.startRunning() // Camera starts capturing + } + + func deactivateCamera() { + captureSession?.stopRunning() // Camera stops capturing + } +} +---- From cd77dee8e640b8bb53b494fae8f2e476cb145422 Mon Sep 17 00:00:00 2001 From: Gilles Grousset Date: Tue, 30 Apr 2024 09:42:39 +0200 Subject: [PATCH 2/4] Added changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba6adfee2..7ec42d9fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#286](https://github.com/green-code-initiative/ecoCode/issues/286) [EC83] [C#] Replace Enum ToString() with nameof - [#27](https://github.com/green-code-initiative/ecoCode-csharp/issues/27) [EC84] [C#] Avoid async void methods - [#34](https://github.com/green-code-initiative/ecoCode-csharp/issues/34) [EC85] [C#] Make type sealed +- [#290](https://github.com/green-code-initiative/ecoCode/issues/290) [EC512] Swift port ### Changed From 84cd7e7b0238943bcc3b4f883e37db365af99dee Mon Sep 17 00:00:00 2001 From: Gilles Grousset Date: Thu, 30 May 2024 13:52:05 +0200 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2a41c557..a6e88ffd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,11 +47,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Swift rules cleanup and updates (removed duplicated rules, added [EC602]) -- [#18](https://github.com/green-code-initiative/ecoCode-csharp/issues/18) [EC81] [C#] Specify struct layout -- [#285](https://github.com/green-code-initiative/ecoCode/pull/285) [EC82] [C#] Cariable can be made constant -- [#286](https://github.com/green-code-initiative/ecoCode/issues/286) [EC83] [C#] Replace Enum ToString() with nameof -- [#27](https://github.com/green-code-initiative/ecoCode-csharp/issues/27) [EC84] [C#] Avoid async void methods -- [#34](https://github.com/green-code-initiative/ecoCode-csharp/issues/34) [EC85] [C#] Make type sealed - [#290](https://github.com/green-code-initiative/ecoCode/issues/290) [EC512] Swift port - [C# #18](https://github.com/green-code-initiative/ecoCode-csharp/issues/18) [EC81] [C#] Specify struct layout - [C# #285](https://github.com/green-code-initiative/ecoCode/pull/285) [EC82] [C#] Variable can be made constant From 37583b8dc9744168fb94d17412070b32196244af Mon Sep 17 00:00:00 2001 From: Gilles Grousset Date: Mon, 3 Jun 2024 09:31:25 +0200 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bf14bf47..d04947814 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#306](https://github.com/green-code-initiative/ecoCode/issues/306) Swift port of rule EC514 - [#315](https://github.com/green-code-initiative/ecoCode/pull/315) Add rule EC530 for javascript - [#321](https://github.com/green-code-initiative/ecoCode/pull/321) Add rule EC522 for javascript (avoid brightness override) +- Swift rules cleanup and updates (removed duplicated rules, added [EC602]) +- [#290](https://github.com/green-code-initiative/ecoCode/issues/290) [EC512] Swift port ### Changed @@ -53,8 +55,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Swift rules cleanup and updates (removed duplicated rules, added [EC602]) -- [#290](https://github.com/green-code-initiative/ecoCode/issues/290) [EC512] Swift port - [C# #18](https://github.com/green-code-initiative/ecoCode-csharp/issues/18) [EC81] [C#] Specify struct layout - [C# #285](https://github.com/green-code-initiative/ecoCode/pull/285) [EC82] [C#] Variable can be made constant - [C# #286](https://github.com/green-code-initiative/ecoCode/issues/286) [EC83] [C#] Replace Enum ToString() with nameof