Working of NSMutableData [closed] - nsmutabledata

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am new to ios development. Please tell me what is NSMutableData and How it works? I have been searching for this question but have not got any perfect answer.

NSMutableData (and its superclass NSData) provide data objects, object-oriented wrappers for byte buffers. Data objects let simple allocated buffers (that is, data with no embedded pointers) take on the behavior of Foundation objects. They are typically used for data storage and are also useful in Distributed Objects applications, where data contained in data objects can be copied or moved between applications. NSData creates static data objects, and NSMutableData creates dynamic data objects. You can easily convert one type of data object to the other with the initializer that takes an NSData object or an NSMutableData object as an argument.
It inherits from
NSobject -> NSData -> NSMutableData

Related

MVVM in SwiftUI and the appropriate Bindings [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
The community is reviewing whether to reopen this question as of 1 year ago.
Improve this question
Edited
Having multiple data sources for an app
What is the best approach to combine all data sources together in one class and add it as one environment object, keeping in mind data might change, therefore objects update the views?
What are the appropriate Bindings to use for:
Services (API fetches): #Published?
Computed variables: Lazy var?
Please refer to the diagram as an example. Thanks.
These questions were good references:
An equivalent to computed properties using #Published in Swift Combine?
https://medium.com/genetec-tech/property-wrappers-in-swift-5-1-the-missing-published-implementation-1a466ebcf660
diagram
So, you should use a layered architecture and you will not have those problems.
service layer, it's the lowest layer reads the data from either web or db, or other services
repository layer gets the data from service and process it, caching, etc
usecase layer combines data from multiple repositories
viewmodel layer gets the data from usecase and sends it to view
each service or repository handles one type of data "Users" for example
now, if you need to combine multiple types of data, like Users and Companies let's say, you need a Usecase layer which will combine all the data
on your viewmodel you only use the usecase layer
One important note, passed objects change between layers, so on service layer you have UserDto (coming from webservice), and UserEntity (coming from DB), the repo will transform those in UserResponse, which you don't know if it's db or webservice and even more the UseCase will transform UserResponse and CompanyReponse into a User object which will be passed to ViewModel and will contain all data required there.
Also, until you get to the viewmodel layer you should not need SwiftUI, if you need it, you are doing something wrong, use Swift Combine to handle data.

Scala: How to write my own mutable array? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I know there is scala.collection.mutable package which provides mutable data structures. But how is it done?
Can I write my own mutable data structure and pass it to a function to be changed?
Edit: The question aims towards techniques that can be used to implement mutable data types.
Read this wonderful tutorial on implementing custom collections in scala.
It should have all you need to answer the question "how it is done".
If you are just talking about any data structure, not a collection, then something like
class Foo(var bar: String)
will do. But ... don't do it. While, there are rare and isolated cases, where having a mutable structure is unavoidable, chances are, you will not encounter such a case for a long time.
My advice to you is to start with learning to write good, idiomatic scala code, and getting into the functional mindset, where data structures don't mutate under you. Learn to appreciate that.
Sure, you can. There is no limitation, that all immutable data structures should be inside scala.collection.immutable, and all mutable DS should be inside scala.collection.mutable. Standard collection classes are divided into these two packages just for convenience. You can create your classes, where you like to do it.

How to design database model in Swift if using Protocol and Struct only? [duplicate]

This question already has answers here:
How to save a struct to realm in swift?
(4 answers)
Closed 6 years ago.
Since Swift Protocol Oriented Programming, struct, value typed and functional programming are improving in Swift. But how about the databases. I have used 2 database: Cora Data and Realm. Both required a class to be inherited from Object (Realm) or ManagedObject(Core Data)
My question is: What is the database model to use If I want to design my application model with struct only?
Thanks
This was asked in a similar question before: How to save a struct to realm in swift?
Suffice it to say, Realm's implementation details (and Core Data as well) rely on the Objective-C runtime, so their models cannot be structs.

Are class members mandatory? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I remember reading (or hearing) somewhere a few years back that classes must have either an operation, an attribute and an operation, or at least an attribute as a mandatory requirement -- not empty. What I'm asking is whether it's a violation of the Software Engineering rules to have an empty class, or a class with either attributes or operations without the other.
I just want to make sure so that my class diagrams are correct for my project.
Thank you.
You can certainly have a class with attributes but no operations and vice versa.
As for a class with no attributes and no operations - Most (all?) OO languages would allow this, but of course such a class wouldn't be terribly useful except perhaps as a base class of some sort.
Engineering is all about breaking the rules and thinking outside the box.
An empty class, without properties (attributes, etc) or methods (operations, etc) is simply that: an abstract datatype which does nothing.
Many if not most type systems provide for such a thing, if one isn't predefined.
If you define your own, you should have a good reason for doing so. In C++ for example a class used as an object or tag in metaprogramming is often completely empty, because it only serves to carry information through the type system or function overloading at compile time, and ideally does not exist at runtime.

What are the pros and cons of two different ways for implementing sections in UITableViewController? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I need to download and parse some XML data, and to store it in sqlite. Then I need to present that data on table view. I'm trying to figure out the most effective way how to present that data further: take form sqlite and use it for table view that also uses a search. Therefore, I need to copy that data from the sqlite "source" into some "table data" property/ies in my table view controller. So, the two common ways are:
To have one NSArray property that contains section names (for example NSString type) and to have NSDictionary property (for storing rows) that keys are the section names contained in the first NSArray.
To have only one nested NSArray property (matrix): NSArray would contain elements that are also NSArrays, and each element in inner NSArray is a type of CustomClass of NSDictionary.
Other ways, please ....
I'm wondering what road should I take and what are pros and cons of those two (and maybe other) ways. Please share your experience and insights.
Why don't you use Core Data to store your data? It uses sqlite as the back-end if the store type of the NSPeristentStoreCoordinator is NSSQLiteStoreType. If you are not familiar with it, make a new project, tick Use Core Data on creation. You will need to spend some time to learn it, but it is worth it. It's all there, storing, searching, filtering, sorting, displaying in a table view, etc.