RLMRealm(path:) Argument labels '(path:)' do not match any available overloads - swift3

I just tried to install the latest version of Realm (2.1.0) for Swift 3 and I'm getting an error on this line: let realm = RLMRealm(path: databasePath) - DataManager.swift:258:21: Argument labels '(path:)' do not match any available overloads
The declaration of the argument is here:
var databasePath : String
I know that swift 3 is requiring label for the first argument, but I've looked everywhere for the replacement and can't find an answer.

+ [RLMRealm realmWithPath:] was an API that was deprecated and entirely removed from Realm many months ago. It was replaced with + [RLMRealm realmWithConfiguration:], where you supply an RLMRealmConfiguration object with the file path to the target file set in its fileURL property.
let configuration = RLMRealmConfiguration.defaultConfiguration()
configuration.fileURL = URL(path: databasePath)
let realm = RLMRealm(configuration: configuration)
On a side note, unless you've got a specific reason for using the Objective-C version of Realm in Swift, I highly recommend you use the native Swift version of Realm instead. That one should be a lot easier, and feel a lot more natural in Swift 3. :)

Related

Why can i create local variables in a view builder in SwiftUI

I think I used to get error complaining about having a local variable in the view builder. I also looked up online and found this:
Closure containing a declaration cannot be used with function builder 'ViewBuilder'
However, today when I tried it out, I was able to create local variables in a view builder without any problem:
#ViewBuilder
private var foo: some View {
let something = 3
Text("foo")
Text("bar")
}
May I know why?
When SwiftUI was first released (in 2019), the Swift language didn't allow local declarations (like let something = 3) inside what were then called “function builders”. However, function builders evolved into what are now called “result builders” and do support local declarations as of Swift 5.4.
This behavior is documented in SE-0289 Result Builders:
Declaration statements
Local declarations are left alone by the transformation. This allows developers to factor out subexpressions freely to clarify their code, without affecting the result builder transformation.

Unable to infer complex closure return type with SwiftUI

Following part 3 of Apple's tutorial on SwiftUI, Handling User Input, I get this error:
Unable to infer complex closure return type; add explicit type to disambiguate
I'm using the same code as the tutorial (even coping from the 'Complete' sample code doesn't resolve the error).
Does anyone have a cue what is going wrong here?
struct LandmarkRow: View {
var landmark: Landmark
var body: some View {
HStack {
landmark.image(forSize: 50)
Text(verbatim: landmark.name)
Spacer()
if landmark.isFavorite {
Image(systemName: "star.fill")
.imageScale(.medium)
}
}
}
}
Regardless of the cause of the issue, how could you indeed add an explicit type to disambiguate here? What would the return type in such a case be?
--
Update
Apparently you should not continue with your result of the 2nd tutorial with the 3rd. Some things changed in between of the tutorials that is not documented in the tutorial. I've added the project files to Github so you can check out the diff.
It's better to start the 3rd tutorial fresh with a fresh download of the Project files of the 3rd tutorial.
The issue is not with the closure, but with the isFavorite property on landmark.
It is not declared on the Landmark type, and the compiler instead of showing the undeclared property error, unable to resolve the stacks build closure return type, so it shows and error there.
Great job Apple tutorial writers and even better one Xcode11 compiler.
To fix:
Declare isFavorite variable on the Landmark type.
Make sure you update the landmarkData.json for every landmark record with the isFavorite = false entry, otherwise the app will crash at runtime.
Some background to this problem
Like #dirtydanee already answered there is a difference between those two tutorials. But the problem behind the problem is that while it looks like you're doing a configuration it's actually just functions nested in functions using generics and protocols to "magically" parse everything into a compiling function.
However conformance to these generics and protocols need to be pretty precise because if not the whole tree of functions cannot compile anymore. But it's hard to determine for the compiler what conformance actually failed. This is why you see an error at the top rather than at the point where it actually happens.
It's strongly advised to make sure your views are decomposed into natural and simple blocks so you're not pouring over hundreds of lines of View code to find that one bug.
Dave DeLong had a really great talk about how to compose Views from ViewControllers that still holds true until today: basically you never use View as a subview inside another View but you need to decompose your View of many, simple Views. Otherwise these errors'll drive you nuts.
For people getting this error on SwiftUI and looking for a way to debug their view stack
This error happens mainly when there is a compilation issue on one child View.
1 - Make sure your parent view can support multiple subviews (VStack, ZStack) and you have less than 10 subviews. Sometime you may want to add a Group wrapper.
2 - If this is not the problem, there is probably an issue with one subview. Try to isolate the one you suspect to have the issue. Usually I copy the subview into a property and a different error appears
var debug: some View {
MyViewWithError(property: self.property)
}
Most of the time you'll encounter this because you pass the property (self.property) instead of a binding (self.$property)
Hope this can help some people
I have run into this error when made a typo. Also this error appears when a code has syntax issues. Just check if your changes are correct
I encountered the problem in a subview where a #Binding prop was of a different type of the #Binding source.

Can't save models to DynamoDB using Swift 4

I started a new project using XCode9 and Swift4. I copied the basic example code for saving models to DynamoDB but I keep getting the following error:
Amazon DynamoDB Save Error: Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=0 "(null)" UserInfo={__type=com.amazon.coral.validate#ValidationException, message=Supplied AttributeValue is empty, must contain exactly one of the supported datatypes}
My project only contains the example code provided and nothing else, how can I get my models to save?
The work-around until Swift 4 is supported properly is to put
#objcMembers
before the class declaration for your model class, as described in this bug report.
https://github.com/aws/aws-sdk-ios/issues/750
This fixed the issue for me without having to downgrade to Swift 3.
DynamoDB doesn't seem to support Swift4 yet. I downloaded the sample project provided by AWS (MySampleApp) and set the target's build settings Swift Language Version to Swift 4.0, made slight modifications so it would compile, and I got the same error.
Reducing the Swift Language Version to Swift 3.2 in both the sample app and my own project fixed the problem.

iOS Swift cannot set AWSSNSSubscribeInput.protocol parameter

I am using Swift for iOS app development in Xcode 6.1.1.
I am trying to programatically subscribe the app to a AWS SNS topic. As I know, you need to set:
let subscriptionRequest = AWSSNSSubscribeInput()
subscriptionRequest.protocol = "application"
subscriptionRequest.topicArn = kMyTopicArn
subscriptionRequest.endpoint = endPointARN
But the problem here is the IDE keeps telling me that
subscriptionRequest.protocol = "application"
is not acceptable and it won't even build.
Really have no idea how to solve this. Could anyone help here? THANKS!
This has something to do with the reserved words in Swift. To escape, just simple wrap the word in ``, e.g.
subscriptionRequest.`protocol` = "application"
See this for more: Reserved Words In Swift and How to Escape Them

Rubymotion support for ruby 2.0 keyword arguments

Does Rubymotion support ruby 2.0 keyword arguments? I have this method and it throws this error: syntax error, unexpected tSTRING_BEG, expecting tIDENTIFIER
def foo(message, offset: 20)
# Do something
end
I am using the following version of Ruby, but it doesnt seem to be working?
$ ruby -v
vruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-darwin13.0.2]
No.
RubyMotion was released before Ruby 2.0.0, but it needed keyword arguments to interoperate with Objective-C, for example to define callback/delegate methods. So it introduced keyword arguments based on one of existing keyword arguments proposals at the time:
def tableView(view, numberOfRowsInSection: section)
# ...
end
So in RubyMotion the argument keyword name (numberOfRowsInSection) is separate from the argument name (section), and if keyword is present in a signature, then it is required.
However, Ruby 2.0.0 decided to stick to a different design:
def foo(message, offset: 0)
# ...
end
Argument keyword name is the same as the argument name (offset), they always have a default value (0 here), and they are optional (you can call foo(message) without offset here).
This is a bit unfortunate. But I'm interested to see how will RubyMotion evolve to support Ruby 2.0.0 keyword arguments in future.
Yes.
Using the Ruby Motion developer center docs as a reference, here's an example that looks a lot like what you're trying to do.
class DrawingProxy
def drawAtPoint(point, withFont:font)
#str.drawAtPoint(point, withFont:font)
end
end
That link explains how Objective-C messages with selectors map to and from RubyMotion, which takes things in a slightly non-Ruby direction in that you can effectively have Ruby methods with identical names "overloaded" as long as they have unique selectors (arguments).
A more RubyMotion way to express your example is:
def foo(message, withOffset = 20)
# Do something
end
You were using ":" (call value) rather than "=" (declare default) syntax.