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

Added Swift version of EC512 #291

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
----
Loading