AFNetworkActivityLogger's level in SWIFT - swift

I have a project in SWIFT where I use AFNetworking and AFNetworkActivityLogger for debugging. I am having troubles to change the "level" attribute. By default it is set to AFLoggerLevelInfo, but I need it to AFLoggerLevelDebug.
I tried the following in my AppDelegate.swift:
AFNetworkActivityLogger.sharedLogger().level = AFLoggerLevelDebug
which results in "Use of unresolved identifier 'AFLoggerLevelDebug'". Anyone knows how to change the level of AFNetworkActivityLogger?

The AFHTTPRequestLoggerLevel is an enum, so you want:
AFNetworkActivityLogger.sharedLogger().level = AFHTTPRequestLoggerLevel.AFLoggerLevelDebug
or
AFNetworkActivityLogger.sharedLogger().level = .AFLoggerLevelDebug

Related

Unable to get IntelliJ's (Velocity) Code Template to work correctly with conditional variable assignment

I am attempting to improve a Scala Companion Object plus Case Class code generating template in IntelliJ 2021.3 (Build #IU-213.5744.223, built on November 27, 2021).
I would like to allow the user to be able to leave some of the input parameters unspecified (empty) and then have the template generate sane defaults. This is because the generated code can then be refactored by the client to something more pertinent later.
My question is this: Is there another way to approach achieving my goal than the way I show below using the Velocity #macro (which I got from here, and then doesn't appear to work anyway)?
With the current approach using the #marco, when I invoke it...
With:
NAME = "Longitude"
PROPERTY_1_VARIABLE = "value"
PROPERTY_1_TYPE - "Double"
The Scala code target:
final case class Longitude(value: Double)
With:
NAME = "Longitude"
PROPERTY_1_VARIABLE = ""
PROPERTY_1_TYPE - ""
The Scala code target using defaults for 2 and 3:
final case class Longitude(property1: Property1Type)
And here's my attempt to make it work with the IntelliJ (Velocity) Code Template:
#macro(condOp $check, $default)
#if ($check == "")
$default
#else
$check
#end
#end
#set (${PROPERTY_1_VARIABLE} = "#condOp(${PROPERTY_1_VARIABLE}, 'property1')")
#set (${PROPERTY_1_TYPE} = "#condOp(${PROPERTY_1_TYPE}, 'Property1Type')")
#if ((${PACKAGE_NAME} && ${PACKAGE_NAME} != ""))package ${PACKAGE_NAME} #end
final case class ${NAME} (${PROPERTY_1_VARIABLE}: ${PROPERTY_1_TYPE})
First, the IntelliJ popup box for entering the parameters correctly shows "Name:". And then incorrectly shows "default:" and "check". I have submitted a ticket with Jetbrains for this IntelliJ issue. Please vote for it, if you get a chance so it increases in priority.
And then when the macro finishes executing (I provide the Name of "LongLat", but leave the default and check parameters empty), I don't understand why I get the following gibberish.
package org.public_domain
${PROPERTY_1_TYPE})
Any guidance on fixing my current Velocity Code Template script or suggest another way to effectively approach solving the problem would be deeply appreciated.

Identify the test device for Admob

I use the code below:
let request : GADRequest = GADRequest ()
request.testDevices = ["xxxxxxx",kGADSimulatorID]
But I am getting the below warning:
'testDevices' is deprecated: Use GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers.
Do I use a syntax to remove the warning?
You should use this:
GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers = ["YOUR IDENTIFIER PRINTED ON DEBUGGER"]
Instead of:
request.testDevices = ["YOUR IDENTIFIER PRINTED ON DEBUGGER"]
Swift Solution
It turns out the AdMob/GoogleAdManager deviceId can be found by computing the MD5 of the advertisingIdentifier. This way you can retrieve and use the test deviceId in code without having to previously have got a device's identifier from the console log.
To avoid the faff of using an ObjC-Swift bridging header (getting MD5 via <CommonCrypto/CommonCrypto.h>), I'd suggest using a Swift wrapper around the CommonCrypto framework, e.g this one:
SwiftCrypto
Using the above framework (which adds an extension property to String for computing the MD5 hash), it is a simple matter of querying against:
GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers ?? []).contains(ASIdentifierManager.shared().advertisingIdentifier.uuidString.md5)
This is a modification to 10623169's answer.
To get a valid ID, for the current device, that can be set in "testDevices", get the MD5 of this: UIDevice.current.identifierForVendor?.uuidString
The asIdentifier value can be completely invalid if the user hasn't given permission for tracking. But the UIDevice.current.identifierForVendor is a valid UUID for the app, that will persist across launches (but perhaps not if you delete the app and reinstall).
Use the syntax to remove the warning:
GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers
You don't have to set this at all. As the AdMob Developer Doc says:
iOS simulators are automatically configured as test devices.
Source: https://developers.google.com/admob/ios/test-ads#enable_test_devices

Use of undeclared unstable module when module is imported and a cfg attribute is used

I have the below code:
#[cfg(all(feature = "unstable", unique))]
#[cfg(all(feature = "unstable", heap_api))]
#[cfg(all(feature = "unstable", alloc))]
use std::ptr::Unique;
use std::mem;
use alloc::heap;
pub struct Foo<T> {
arr: Unique<T>,
cap: usize,
probe_limit: usize,
}
However, when I try to compile it with cargo build --features "unstable" I get a compilation error. Note that I am using the nightly build of Rust and the unstable feature is set up correctly (otherwise I would get a different error).
error[E0412]: cannot find type `Unique` in this scope
--> src/hash/arr.rs:27:8
|
27 | arr: Unique<T>,
| ^^^^^^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope
| use std::ptr::Unique;
I'm not sure why Unique is not found. I am should be using it at the top of my file. use ::std::ptr::Unique does not work.
Let's deconstruct your cfg instruction:
#[cfg(all(feature = "unstable", unique))]
This is an outer attribute, meaning it is outside the item it will change, and will apply to the next item. With the cfg attribute, it means "if the feature inside the parenthesis is enabled, do the next block", and all is a AND between the features. So you have something like "if features unstable and unique are enabled, do the next statement.
Attributes! What you want is to have the inner attribute feature(unique) conditionally if you have set the feature unstable on the command line. A conditional attribute can be obtained with cfg_attr.
#![cfg_attr(feature = "unstable", feature(unique))]
This can be read as if feature unstable is enabled, then enable the inner feature(unique). Then you will be able to use std::ptr::Unique.
You should also add a #[cfg(feature = "unstable")] before the use and your struct, so that they won't be usable if the feature is not enabled.

ASImageNode - Cannot assign to property: 'image' is a get-only property

I'm converting my iOS Project from Swift 2.2 to Swift 3. Everything was going well, but when I tried to set image to an instance of ASImageNode, I got an error that said: "Cannot assign to property: 'image' is a get-only property".
Here is my code:
let imageNode = ASImageNode()
imageNode.image = myImage
However, it worked in Xcode 7 + Swift 2.2.
I checked the definition of the image by 'cmd+click', but Xcode brought me to the -(CIImage *)image; in CIImageAccumulator.h instead of image in ASImageNode.
I could access other class and property in AsyncDisplayKit properly but ASImageNode.image. If I commented all lines with accessing ASImageNode.image, my project was built successfully.
the solution that worked for me is updating this library .. just update all dependencies that use UIImage , it looks like there's no other solution.
"var imageee:UIImage?"
Initialize by this Hope Worked for you
solved my problem by this way

Use of Unresolved Identifier adding second pin MapKit swift

I am trying to add another pin to my map.
It has worked fine with
artworkPin = Artwork(title:"Wind Wand",locationName:"Majestic",discipline:"Statue",
coordinate:windwandcoord)
but now I've tried adding
artworkPin2 = Artwork(title:"Wind Wand2",locationName:" Not Majestic",discipline:"Statue",
coordinate:windwandcoord2)
but this is giving me an error of Use of unresolved identifier 'artworkPin2'
Any thoughts on what might be causing this?
The error means there is no variable named artworkPin2 in the current scope.
So assuming you are creating a new, local variable, you need to use var (or let):
var artworkPin2 = Artwork(title:"Wind Wand2",locationName:" Not Majestic",discipline:"Statue",
coordinate:windwandcoord2)
Or perhaps you need to add a property named artworkPin2 to your class and assign to that property.