如何在Objective-C中的字典中存储数组。我如何修改我的代码?
##Server.r
shinyServer(function(input, output, session) {
output$chk.output <- renderUI(checkboxGroupInput("Chk", label = "Choices", choices = list("1" = 1, "2" = 2, "3"= 3, "4"=4, "5"=5), selected = input$s1, inline = TRUE, width = "100%"))
selectGrEv <- reactiveValues(aa=0)
observeEvent(input$s1,{
selectGrEv$aa=input$s1
})
observeEvent(input$refresh,{
selectGrEv$aa=input$Chk
})
output$myplot <- renderPlot({
plot(1:5, 1:5)
if (1 %in% selectGrEv$aa) {text(1,1, labels= 1, col = "red", pos = 3)}
if (2 %in% selectGrEv$aa) {text(2,2, labels= 2, col = "blue", pos = 3)}
if (3 %in% selectGrEv$aa) {text(3,3, labels= 3, col = "black", pos = 3)}
if (4 %in% selectGrEv$aa) {text(4,4, labels= 4, col = "orange", pos = 3)}
if (5 %in% selectGrEv$aa) {text(5,5, labels= 5, col = "green", pos = 1)}
})
})
答案 0 :(得分:1)
坚持使用变量名称,它使您的代码可读并且不容易出错。
如果你有一个名为&#34; studentArray&#34;那么它应该只存储Student
类的对象。
Student *firstStudent = ....;
Student *secondStudent = .... ;
NSArray *studentArray = @[firstStudent, secondStudent];
现在您要将此数组存储在字典中:
NSDictioanary *someDictionary = @{@"studentArrayKey" : studentArray
@"otherKey" : @"otherObject",
};
编辑:
如果按照Obj-C命名约定将studentArray
命名为students
,那将是很好的。当命名为复数时,所有集合听起来都不错。