title: Generic variable inside generic class returns empty
body: <p>When the getUserDefaults function works, when I call the &quot;allQuestionList&quot; variable inside the other view, it returns empty.
  What is the reason of this ?
  I want T to assign whatever model I give it to &quot;allQuestionList&quot;.</p>
  <pre><code>class UserDefaultsStore&lt;T: Codable&gt;: ObservableObject {
  
      @Published var allQuestionList: T?
      
      func setUserDefaults(forkey key: String) {
          let jsonEncoder = JSONEncoder()
          if let encoded = try? jsonEncoder.encode(allQuestionList) {
              UserDefaults.standard.set(encoded, forKey: key)
          }
      }
      
      func getUserDefaults(forKey key: String) {
          if let questions = UserDefaults.standard.data(forKey: key) {
              let decoder = JSONDecoder()
              if let decode = try? decoder.decode(T.self, from: questions) {
                  self.allQuestionList = decode
              }
          }
      }
      
      func removeUserDefaults(forKey key: String) {
          UserDefaults.standard.removeObject(forKey: key)
      }
      
      func isKeyPresentInUserDefaults(key: String) -&gt; Bool {
          return UserDefaults.standard.object(forKey: key) != nil
      }
  }
  </code></pre>
  <p><strong>Example:</strong></p>
  <p>Let's take the User model for example.</p>
  <p>If I run the application without assigning the User model, then it returns null. Whenever I assign a value when the application is opened, then it returns a full value.</p>
  <pre><code>Nil -&gt; @Published var userQuestions: User?
  </code></pre>
  <p>However, the variable here is successfully assigned.</p>
  <pre><code>class UserDefaultsStore&lt;T: Codable&gt;: ObservableObject {
      @Published var userQuestions: User = User(uid: &quot;&quot;, questions: UserQuiz(title: &quot;&quot;, test: []), wrongQuestions: [])
      .....
  }
  </code></pre>
  <p><strong>User Model:</strong></p>
  <pre><code>struct User: Codable {
      var uid: String
      var questions: UserQuiz?
      var wrongQuestions: [UserQuestionList]?
  }
  
  struct UserQuiz: Codable {
      var title: String?
      var test: [UserQuestionList]?
  }
  
  struct UserQuestionList: Codable {
      var id: Int?
      var question: String?
      var isQuestionImage, isSectionImage: Bool?
      var imageURL: String?
      var sections: [UserQuestionSections.RawValue : String]?
      var selected: String?
      var correct: String?
  }
  
  enum UserQuestionSections: String, Codable, Hashable {
      case A = &quot;A&quot;
      case B = &quot;B&quot;
      case C = &quot;C&quot;
      case D = &quot;D&quot;
  }
  </code></pre>
  <p><strong>Quiz Model:</strong></p>
  <pre><code>struct QuizContainer: Codable, Hashable {
      var allQuiz: [Quiz]?
  }
  
  struct Quiz: Codable, Hashable {
      var title: String?
      var id: String
  }
  </code></pre>
  <p><strong>Example:</strong></p>
  <p>I use it this way, but the variable allQuestionList returns empty to me.</p>
  <pre><code>struct QuestionListView: View {
      ...
      @EnvironmentObject var userDefaultsStore: UserDefaultsStore&lt;User&gt;
      ...
      var body: some View {
          ScrollView(.vertical, showsIndicators: false) {
          
  
            ForEach(userDefaultsStore.allQuestionList?.questions?.test?.indices ?? 0..&lt;0, id: \.self) { index in {
  ...
  }
  
  
          }
      }
  }
  </code></pre>