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 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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