multiple map with rxswift
I am trying to create sections for a tableview from an array of item on which each array item is a sections item.
My quesiton is how can I make
cart.map
return an array of
CartProductSection ([CartProductSection]) instead of assign it to a variable. Thanks.
My code
let cart: BehaviorRelay
struct Output {
let items: Observable<[CartProductSection]>
}
var sectionPerSupplierItems: [CartProductSection] =
_ = cart.map { (cart) in
let cartItemsPerSupplier = self.sortModelItemPerSection(items: cart.items)
print(cart.items.count)
_ = cartItemsPerSupplier.map { (cartItemsPerSupplier) in
var items: [CartProductSectionItem] =
for cartItem in cartItemsPerSupplier.cartItems {
items.append(CartProductSectionItem.cartItem(viewModel: CartItemViewModel(with: cartItem)))
}
sectionPerSupplierItems.append(CartProductSection.cartItemModel
(title: cartItemsPerSupplier.companyName, items: items))
}
}
return Output(items: Observable.just(sectionPerSupplierItems))
ios swift reactive-programming rx-swift
add a comment |
I am trying to create sections for a tableview from an array of item on which each array item is a sections item.
My quesiton is how can I make
cart.map
return an array of
CartProductSection ([CartProductSection]) instead of assign it to a variable. Thanks.
My code
let cart: BehaviorRelay
struct Output {
let items: Observable<[CartProductSection]>
}
var sectionPerSupplierItems: [CartProductSection] =
_ = cart.map { (cart) in
let cartItemsPerSupplier = self.sortModelItemPerSection(items: cart.items)
print(cart.items.count)
_ = cartItemsPerSupplier.map { (cartItemsPerSupplier) in
var items: [CartProductSectionItem] =
for cartItem in cartItemsPerSupplier.cartItems {
items.append(CartProductSectionItem.cartItem(viewModel: CartItemViewModel(with: cartItem)))
}
sectionPerSupplierItems.append(CartProductSection.cartItemModel
(title: cartItemsPerSupplier.companyName, items: items))
}
}
return Output(items: Observable.just(sectionPerSupplierItems))
ios swift reactive-programming rx-swift
There's not enough context to go on. What is the type ofcart
? Are you usingRxDataSources
? What type are you expecting to feed into the table view?
– Daniel T.
Dec 31 '18 at 14:01
code updated, yes am using rxdatasrouce.
– Mohamed ALOUANE
Dec 31 '18 at 14:10
add a comment |
I am trying to create sections for a tableview from an array of item on which each array item is a sections item.
My quesiton is how can I make
cart.map
return an array of
CartProductSection ([CartProductSection]) instead of assign it to a variable. Thanks.
My code
let cart: BehaviorRelay
struct Output {
let items: Observable<[CartProductSection]>
}
var sectionPerSupplierItems: [CartProductSection] =
_ = cart.map { (cart) in
let cartItemsPerSupplier = self.sortModelItemPerSection(items: cart.items)
print(cart.items.count)
_ = cartItemsPerSupplier.map { (cartItemsPerSupplier) in
var items: [CartProductSectionItem] =
for cartItem in cartItemsPerSupplier.cartItems {
items.append(CartProductSectionItem.cartItem(viewModel: CartItemViewModel(with: cartItem)))
}
sectionPerSupplierItems.append(CartProductSection.cartItemModel
(title: cartItemsPerSupplier.companyName, items: items))
}
}
return Output(items: Observable.just(sectionPerSupplierItems))
ios swift reactive-programming rx-swift
I am trying to create sections for a tableview from an array of item on which each array item is a sections item.
My quesiton is how can I make
cart.map
return an array of
CartProductSection ([CartProductSection]) instead of assign it to a variable. Thanks.
My code
let cart: BehaviorRelay
struct Output {
let items: Observable<[CartProductSection]>
}
var sectionPerSupplierItems: [CartProductSection] =
_ = cart.map { (cart) in
let cartItemsPerSupplier = self.sortModelItemPerSection(items: cart.items)
print(cart.items.count)
_ = cartItemsPerSupplier.map { (cartItemsPerSupplier) in
var items: [CartProductSectionItem] =
for cartItem in cartItemsPerSupplier.cartItems {
items.append(CartProductSectionItem.cartItem(viewModel: CartItemViewModel(with: cartItem)))
}
sectionPerSupplierItems.append(CartProductSection.cartItemModel
(title: cartItemsPerSupplier.companyName, items: items))
}
}
return Output(items: Observable.just(sectionPerSupplierItems))
ios swift reactive-programming rx-swift
ios swift reactive-programming rx-swift
edited Dec 31 '18 at 14:10
Mohamed ALOUANE
asked Dec 31 '18 at 12:52
Mohamed ALOUANEMohamed ALOUANE
2,45721740
2,45721740
There's not enough context to go on. What is the type ofcart
? Are you usingRxDataSources
? What type are you expecting to feed into the table view?
– Daniel T.
Dec 31 '18 at 14:01
code updated, yes am using rxdatasrouce.
– Mohamed ALOUANE
Dec 31 '18 at 14:10
add a comment |
There's not enough context to go on. What is the type ofcart
? Are you usingRxDataSources
? What type are you expecting to feed into the table view?
– Daniel T.
Dec 31 '18 at 14:01
code updated, yes am using rxdatasrouce.
– Mohamed ALOUANE
Dec 31 '18 at 14:10
There's not enough context to go on. What is the type of
cart
? Are you using RxDataSources
? What type are you expecting to feed into the table view?– Daniel T.
Dec 31 '18 at 14:01
There's not enough context to go on. What is the type of
cart
? Are you using RxDataSources
? What type are you expecting to feed into the table view?– Daniel T.
Dec 31 '18 at 14:01
code updated, yes am using rxdatasrouce.
– Mohamed ALOUANE
Dec 31 '18 at 14:10
code updated, yes am using rxdatasrouce.
– Mohamed ALOUANE
Dec 31 '18 at 14:10
add a comment |
1 Answer
1
active
oldest
votes
I would likely write the code like this (I'm still making a bunch of assumptions here.):
let items = cart
.map { [unowned self] in self.sortModelItemPerSection(items: $0.items) }
.map { cartItemsPerSuppliers in
cartItemsPerSuppliers.map { CartProductSection.cartItemModel(from: $0) }
}
return Output(items: items)
The above assumes something like this exists:
extension CartProductSection {
static func cartItemModel(from supplier: CartItemsPerSupplier) -> CartProductSection {
return cartItemModel(title: supplier.companyName, items: supplier.cartItems.map { CartProductSectionItem.cartItem(viewModel: CartItemViewModel(with: $0)) })
}
}
Also, if I were writing this, I would movesortModelItemPerSection(items:)
out of the class so I didn't have to referenceself
.
– Daniel T.
Jan 1 at 2:32
Thank you! I got to learn new stuff from this :). Happy new year!
– Mohamed ALOUANE
Jan 1 at 13:33
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53987750%2fmultiple-map-with-rxswift%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I would likely write the code like this (I'm still making a bunch of assumptions here.):
let items = cart
.map { [unowned self] in self.sortModelItemPerSection(items: $0.items) }
.map { cartItemsPerSuppliers in
cartItemsPerSuppliers.map { CartProductSection.cartItemModel(from: $0) }
}
return Output(items: items)
The above assumes something like this exists:
extension CartProductSection {
static func cartItemModel(from supplier: CartItemsPerSupplier) -> CartProductSection {
return cartItemModel(title: supplier.companyName, items: supplier.cartItems.map { CartProductSectionItem.cartItem(viewModel: CartItemViewModel(with: $0)) })
}
}
Also, if I were writing this, I would movesortModelItemPerSection(items:)
out of the class so I didn't have to referenceself
.
– Daniel T.
Jan 1 at 2:32
Thank you! I got to learn new stuff from this :). Happy new year!
– Mohamed ALOUANE
Jan 1 at 13:33
add a comment |
I would likely write the code like this (I'm still making a bunch of assumptions here.):
let items = cart
.map { [unowned self] in self.sortModelItemPerSection(items: $0.items) }
.map { cartItemsPerSuppliers in
cartItemsPerSuppliers.map { CartProductSection.cartItemModel(from: $0) }
}
return Output(items: items)
The above assumes something like this exists:
extension CartProductSection {
static func cartItemModel(from supplier: CartItemsPerSupplier) -> CartProductSection {
return cartItemModel(title: supplier.companyName, items: supplier.cartItems.map { CartProductSectionItem.cartItem(viewModel: CartItemViewModel(with: $0)) })
}
}
Also, if I were writing this, I would movesortModelItemPerSection(items:)
out of the class so I didn't have to referenceself
.
– Daniel T.
Jan 1 at 2:32
Thank you! I got to learn new stuff from this :). Happy new year!
– Mohamed ALOUANE
Jan 1 at 13:33
add a comment |
I would likely write the code like this (I'm still making a bunch of assumptions here.):
let items = cart
.map { [unowned self] in self.sortModelItemPerSection(items: $0.items) }
.map { cartItemsPerSuppliers in
cartItemsPerSuppliers.map { CartProductSection.cartItemModel(from: $0) }
}
return Output(items: items)
The above assumes something like this exists:
extension CartProductSection {
static func cartItemModel(from supplier: CartItemsPerSupplier) -> CartProductSection {
return cartItemModel(title: supplier.companyName, items: supplier.cartItems.map { CartProductSectionItem.cartItem(viewModel: CartItemViewModel(with: $0)) })
}
}
I would likely write the code like this (I'm still making a bunch of assumptions here.):
let items = cart
.map { [unowned self] in self.sortModelItemPerSection(items: $0.items) }
.map { cartItemsPerSuppliers in
cartItemsPerSuppliers.map { CartProductSection.cartItemModel(from: $0) }
}
return Output(items: items)
The above assumes something like this exists:
extension CartProductSection {
static func cartItemModel(from supplier: CartItemsPerSupplier) -> CartProductSection {
return cartItemModel(title: supplier.companyName, items: supplier.cartItems.map { CartProductSectionItem.cartItem(viewModel: CartItemViewModel(with: $0)) })
}
}
answered Jan 1 at 2:03
Daniel T.Daniel T.
13.7k22734
13.7k22734
Also, if I were writing this, I would movesortModelItemPerSection(items:)
out of the class so I didn't have to referenceself
.
– Daniel T.
Jan 1 at 2:32
Thank you! I got to learn new stuff from this :). Happy new year!
– Mohamed ALOUANE
Jan 1 at 13:33
add a comment |
Also, if I were writing this, I would movesortModelItemPerSection(items:)
out of the class so I didn't have to referenceself
.
– Daniel T.
Jan 1 at 2:32
Thank you! I got to learn new stuff from this :). Happy new year!
– Mohamed ALOUANE
Jan 1 at 13:33
Also, if I were writing this, I would move
sortModelItemPerSection(items:)
out of the class so I didn't have to reference self
.– Daniel T.
Jan 1 at 2:32
Also, if I were writing this, I would move
sortModelItemPerSection(items:)
out of the class so I didn't have to reference self
.– Daniel T.
Jan 1 at 2:32
Thank you! I got to learn new stuff from this :). Happy new year!
– Mohamed ALOUANE
Jan 1 at 13:33
Thank you! I got to learn new stuff from this :). Happy new year!
– Mohamed ALOUANE
Jan 1 at 13:33
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53987750%2fmultiple-map-with-rxswift%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
There's not enough context to go on. What is the type of
cart
? Are you usingRxDataSources
? What type are you expecting to feed into the table view?– Daniel T.
Dec 31 '18 at 14:01
code updated, yes am using rxdatasrouce.
– Mohamed ALOUANE
Dec 31 '18 at 14:10