Comments (21)
ObjectMapper seems like such a natural partner for Siesta, I’ve heard people talk about it — but I haven’t used it myself, and don’t know of any example code.
Could your problem be as simple as missing parens?
configureTransformer("/profile/") {
Mapper<User>().map($0.content as JSON)
}
Also, it’s not clear to me that ObjectMapper works with SwiftyJSON — but you should be able to pass it a raw dict as parsed by Siesta:
configureTransformer("/profile/") {
Mapper<User>().map($0.jsonDict)
}
from siesta.
Ah, yes the parens definitely needed to be added, but does not fix the problem. Unfortunately removing the global SwiftyJSON transformer and instead using the raw jsonDict seems to have the same problem too. Investigations ongoing...
from siesta.
Some progress!
configureTransformer("/profile/") {
Mapper<User>().map($0.content as Dictionary)
}
this is close! , but now I'm having trouble grabbing the data from the resource in the closure. currently using this, which does not work.:
if let user: User = resource.typedContent() {
self?.refreshText(user)
}
or this:
if let user = resource.latestData?.content as? User {
self?.refreshText(user)
}
refresh text is never called in either case, but I do see the below in the debugger, so I know that the object is in there somewhere...
is there a good way to get at it?
from siesta.
ok this seems to fully work for accessing the data. it seems like one too many unwraps, but since resource.latestData.content ends up as a User? from the transformer, I ended up with this:
if let optionalUser: User? = resource.typedContent() {
if let user = optionalUser {
self?.refreshText(user)
}
}
for reference from the previous posts, this was the ObjectMapper call that worked in configureTransformer:
configureTransformer("/profile/") {
Mapper<User>().map($0.content as Dictionary)
}
from siesta.
Ah, yes, welcome to the wonderful world of Swift’s type inference: 80% awesome, 20% wat?! Anyway, glad you figured it out.
I’m puzzled that this didn’t compile:
if let user: User = resource.typedContent() {
It works for me when I try to construct a parallel case. I’m wondering … does this compile for you?
if let user = resource.typedContent() as User? {
What about this one (even though it obviously always returns nil)?
if let text: String = resource.typedContent() {
from siesta.
Sorry! I should have been more clear, all of your examples do indeed compile, but none of them succeed in unwrapping at runtime.
I think the second one:
if let user = resource.typedContent() as User? {
should work, based on what I see in the debugger, but it fails to unwrap like the others.
from siesta.
Hmm, looking a little closer at the ObjectMapper API, I think Siesta is giving you content of type User??
. Yuck.
Would you mind running this check to verify the theory?
print("--------->", resource.latestData?.content.dynamicType)
If you see Optional(Swift.Optional<MyProject.User>)
, then bingo.
(Minor aside: it’s both legal and idiomatic Swift to say if let user = user
. The non-optional one shadows the optional one within the if’s body, so you don’t have to define a separate optionalUser
.)
from siesta.
Yup, with that print()
---------> Optional(Swift.Optional<SwiftAPI.User>)
also, appreciate the tip on optionalUser.
from siesta.
OK, thanks! I think that’s something I can address in Siesta. I’ll send you a fix on a branch to test when I’ve had a chance to sit down with it.
from siesta.
thanks, looking forward to it!
from siesta.
I think I’ve fixed this on master. Give it a whirl if you get a chance, and let me know if you’re still getting the double optional!
from siesta.
Confirmed as fixed, sorry for the delay. much appreciated @pcantrell
---------> Optional(SwiftAPI.User)
from siesta.
No worries. Thanks for verifying!
from siesta.
@pcantrell just curious, any plans to properly add a release with this change?
from siesta.
It will be in the next beta for sure, though Siesta work is on hold for a couple of weeks for the start of the semester.
from siesta.
got it. thanks!
from siesta.
Is this change included in the latest released version?
from siesta.
@o15a3d4l11s2 No, you’ll have to use master for now.
from siesta.
@pcantrell Hi,
This fix has not been merged to V1.0 right?
Which installation method should I follow to use master branch?
I am using cocoapod.
Thanks.
from siesta.
@yehe01, if using Cocoapods, you could set the pod as
pod 'Siesta', :git=>'https://github.com/bustoutsolutions/siesta'
This will make Cocoapods use the master branch.
from siesta.
This was merged and released over a year ago. If you’re having trouble with double optionals, please file a new issue with a reproducible test case.
from siesta.
Related Issues (20)
- Possible memory leak in ProgressTracker HOT 13
- tvOS Carthage compilation broken for Xcode 9 HOT 2
- Swift 4.2 + Xcode 10 HOT 5
- Pods/Siesta/Source/Siesta/Support/WeakCache.swift:14:66: 'UIApplicationDidReceiveMemoryWarning' has been renamed to 'UIApplication.didReceiveMemoryWarningNotification' HOT 1
- Pods/Siesta/Source/Siesta/Support/WeakCache.swift:14:42: Type 'NSNotification.Name' has no member 'UIApplication' HOT 1
- Readme 404 link HOT 2
- unexpected duplicate task error for new Xcode build system from Xcode 10 IOS 12.0.1 HOT 1
- How to refresh same web service ?
- Wildcard in PipelineStage.add(_, contentTypes:) doesn't work as expected
- RemoteImageView placeholderImage not showing when imageResource or ImageURL is nil HOT 2
- File-based caching for Siesta HOT 4
- Unexpected version number in 'available' attribute for non-specific platform '*' HOT 2
- Cached Resource timestamp refresh after loading
- Proposal: More elegant way to avoid memory leak in closures HOT 4
- Y'all got wiki-spammed HOT 2
- Chained request progress support
- 404 errors from a resource don't clear as expected from a resource("static url").load()
- Xcode SPM will not accept Quick@around-each dependency HOT 7
- The package product 'Alamofire' requires minimum platform version 10.0 for the tvOS platform, but this target supports 9.0 HOT 3
- Quick dependancy is not correctly versioned HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from siesta.