Contextual Member Has No Associated Value in Swift 3

Contextual member has no associated value in Swift 3

In Swift 3 .redColor() is changed to just .red.

 $0.backgroundColor = .red

For more detail about this read Apple Documentation on UIColor under Symbols section check Type Properties.

Sharing on WhatsApp in Swift 3.0 Error: Contextual member 'urlHostAllowed' has no associated value

You need to get rid of the "()" in the third line:

let urlStringEncoded = urlString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed())

to this:

let urlStringEncoded = urlString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)

SwiftUI: Cannot infer contextual base in reference to member

As @jnpdx is referring to with the Xcode versions, the Swift version may not be the same. In Swift 5.4, SE-0287 was implemented.

This proposal allowed for implicit member chains. You can read more on the proposal linked, but this sums it up pretty well:

This proposal suggests the expansion of implicit member syntax to more complex expressions than just a single static member or function. Specifically, implicit member syntax would be allowed to cover chains of member references.

Code such as Color.red.opacity(0.5) can now be simplified to .red.opacity(0.5), similar to in your example.

Xcode 12.5 is required to use Swift 5.4, so let the team know to upgrade.

Array.map() produces '[T]', not the expected contextual result type '[String: Any?]'

Your problem lies with the fact, that map always returns an Array, even when applied on a Dictionary. Your error message basically means, that you declared your method as returning a Dicitonary, but the statement inside returns an Array ([T] - means an Array with objects of some type T). In your case, the array returned by map will contain tuples (more about them here). In this case it looks like a key value pair, but its not equivalent to a key-value pair inside a Dictionary. Basically, tuples enable you to return more than one value/object from method. You can think of them as of anonymous structures.

In my opinion, there is no need to use a map to accomplish what you need - the solution provided by Mr. Xcoder is the way to go.

Reference to member 'subscript' cannot be resolved without a contextual type

Try using the subscript on the test array, rather than on the result of Int initializer:

var test = ["1", "2"]
let test1 = Int(test[0])
let test2 = Int(test[1])

However, you can achieve what you are trying in an more swifty way:

var test = ["1", "2"]
print(test.compactMap(Int.init).reduce(0, +))

Or with just reduce(_:_:):

var test = ["1", "2"]
print(test.reduce(0) { $0 + (Int($1) ?? .zero) })

Ambigious reference to member request() issues with Alamofire after migration to swift 3

I have Alamofire swift3 branch working in Xcode 8.0 ß6 with the following code:

Alamofire.request("https://\(ip)/api/version", withMethod: .get, 
parameters: nil, encoding: .json, headers: headers)
.validate()
.responseJSON { response in
//debugPrint(response)
switch response.result {
case .success:
if let JSON = response.result.value {
let version = Mapper<Version>().map(JSON)
print("Version \(version?.server!)")
}
case .failure(let error):
print (error)
}
}

Pay close attention to the order and types of your arguments to .request

You should have only one Alamofire framework active. Try to redo it in another clone, or maybe try the following in the clone you have?

pod cache clean --all
pod install

What does your Podfile have in it?

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target 'NewApp' do
pod 'Alamofire',
:git => 'https://github.com/Alamofire/Alamofire.git',
:branch => 'swift3'
end


Related Topics



Leave a reply



Submit