diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bb16b808..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,7 +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]) - [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 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 + } +} +----