swift - difference between NSObject and Struct -
swift - difference between NSObject and Struct -
i want know difference between nsobject
, struct
..following illustration explain both cases
in struct
struct userdetails{ var username:string var userid:string var userage:string func userdescription()->string{ homecoming "name " + username + "age " + userage } }
in nsobject
class
class userdetails: nsobject { var username:string? var userid:string? var userage:string? func userdescription()->string{ homecoming "name " + username! + "age " + userage! } }
can please tell me have utilize nsobject
class, have utilize struct
..?
classes , structs in swift much closer in many languages. both can have properties, method, initializers, subscripts, can conform protocols, , can extended. however, classes can take advantage of inheritance , utilize deinitializers, , because classes used reference, can have more 1 reference particular instance.
structs used throughout swift -- arrays, dictionaries, optional, , more built on struct
type, performance should high. can utilize struct
whenever don't need inheritance or multiple references classes provide.
struct swift ios8
Comments
Post a Comment