NSString value not persistent
up vote
0
down vote
favorite
I am declaring class variable of type NSString in my "class.h":
@interface class : NSObject<GADInterstitialDelegate,
GADBannerViewDelegate, GADRewardBasedVideoAdDelegate,
GADNativeAppInstallAdLoaderDelegate, GADNativeContentAdLoaderDelegate>
{
...
NSString* appId;
}
I the "class.mm" file In function "a" i am assigning a value to the variable:
appId = [[dic objectForKey:@"appid"] stringValue]
The string value at this point is correct.
The problem happen when other function call - function "b".
[GoogleMobileAdsMediationTestSuite presentWithAppID:appId onViewController:rootViewController delegate:nil];
when i try to use this appId - it doesn't contain the assigned, instead I assume it contain a memory address.
How can I keep the value of appId
in all future references?
ios objective-c nsstring
|
show 4 more comments
up vote
0
down vote
favorite
I am declaring class variable of type NSString in my "class.h":
@interface class : NSObject<GADInterstitialDelegate,
GADBannerViewDelegate, GADRewardBasedVideoAdDelegate,
GADNativeAppInstallAdLoaderDelegate, GADNativeContentAdLoaderDelegate>
{
...
NSString* appId;
}
I the "class.mm" file In function "a" i am assigning a value to the variable:
appId = [[dic objectForKey:@"appid"] stringValue]
The string value at this point is correct.
The problem happen when other function call - function "b".
[GoogleMobileAdsMediationTestSuite presentWithAppID:appId onViewController:rootViewController delegate:nil];
when i try to use this appId - it doesn't contain the assigned, instead I assume it contain a memory address.
How can I keep the value of appId
in all future references?
ios objective-c nsstring
2
can you add some additional code
– Anbu.karthik
yesterday
Checking at this code tell me there is no issue. Search forappId
and check if it's value is updated some where else, also show code were you are displaying to value of appId.
– rptwsthi
yesterday
Is appId a member variable? If yes, are you calling the functions a and b on the same object?
– SSB95
yesterday
@rptwsthi can it be that the app id value is being cleared when dic (dictionary) is being cleared? So when the net function calls and dic is no longer valid the appId value points to unfilled address?
– Michael A
yesterday
Please show the whole definition. How is that "class variable" declared?
– Sulthan
yesterday
|
show 4 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am declaring class variable of type NSString in my "class.h":
@interface class : NSObject<GADInterstitialDelegate,
GADBannerViewDelegate, GADRewardBasedVideoAdDelegate,
GADNativeAppInstallAdLoaderDelegate, GADNativeContentAdLoaderDelegate>
{
...
NSString* appId;
}
I the "class.mm" file In function "a" i am assigning a value to the variable:
appId = [[dic objectForKey:@"appid"] stringValue]
The string value at this point is correct.
The problem happen when other function call - function "b".
[GoogleMobileAdsMediationTestSuite presentWithAppID:appId onViewController:rootViewController delegate:nil];
when i try to use this appId - it doesn't contain the assigned, instead I assume it contain a memory address.
How can I keep the value of appId
in all future references?
ios objective-c nsstring
I am declaring class variable of type NSString in my "class.h":
@interface class : NSObject<GADInterstitialDelegate,
GADBannerViewDelegate, GADRewardBasedVideoAdDelegate,
GADNativeAppInstallAdLoaderDelegate, GADNativeContentAdLoaderDelegate>
{
...
NSString* appId;
}
I the "class.mm" file In function "a" i am assigning a value to the variable:
appId = [[dic objectForKey:@"appid"] stringValue]
The string value at this point is correct.
The problem happen when other function call - function "b".
[GoogleMobileAdsMediationTestSuite presentWithAppID:appId onViewController:rootViewController delegate:nil];
when i try to use this appId - it doesn't contain the assigned, instead I assume it contain a memory address.
How can I keep the value of appId
in all future references?
ios objective-c nsstring
ios objective-c nsstring
edited yesterday
asked yesterday
Michael A
2,4641247103
2,4641247103
2
can you add some additional code
– Anbu.karthik
yesterday
Checking at this code tell me there is no issue. Search forappId
and check if it's value is updated some where else, also show code were you are displaying to value of appId.
– rptwsthi
yesterday
Is appId a member variable? If yes, are you calling the functions a and b on the same object?
– SSB95
yesterday
@rptwsthi can it be that the app id value is being cleared when dic (dictionary) is being cleared? So when the net function calls and dic is no longer valid the appId value points to unfilled address?
– Michael A
yesterday
Please show the whole definition. How is that "class variable" declared?
– Sulthan
yesterday
|
show 4 more comments
2
can you add some additional code
– Anbu.karthik
yesterday
Checking at this code tell me there is no issue. Search forappId
and check if it's value is updated some where else, also show code were you are displaying to value of appId.
– rptwsthi
yesterday
Is appId a member variable? If yes, are you calling the functions a and b on the same object?
– SSB95
yesterday
@rptwsthi can it be that the app id value is being cleared when dic (dictionary) is being cleared? So when the net function calls and dic is no longer valid the appId value points to unfilled address?
– Michael A
yesterday
Please show the whole definition. How is that "class variable" declared?
– Sulthan
yesterday
2
2
can you add some additional code
– Anbu.karthik
yesterday
can you add some additional code
– Anbu.karthik
yesterday
Checking at this code tell me there is no issue. Search for
appId
and check if it's value is updated some where else, also show code were you are displaying to value of appId.– rptwsthi
yesterday
Checking at this code tell me there is no issue. Search for
appId
and check if it's value is updated some where else, also show code were you are displaying to value of appId.– rptwsthi
yesterday
Is appId a member variable? If yes, are you calling the functions a and b on the same object?
– SSB95
yesterday
Is appId a member variable? If yes, are you calling the functions a and b on the same object?
– SSB95
yesterday
@rptwsthi can it be that the app id value is being cleared when dic (dictionary) is being cleared? So when the net function calls and dic is no longer valid the appId value points to unfilled address?
– Michael A
yesterday
@rptwsthi can it be that the app id value is being cleared when dic (dictionary) is being cleared? So when the net function calls and dic is no longer valid the appId value points to unfilled address?
– Michael A
yesterday
Please show the whole definition. How is that "class variable" declared?
– Sulthan
yesterday
Please show the whole definition. How is that "class variable" declared?
– Sulthan
yesterday
|
show 4 more comments
3 Answers
3
active
oldest
votes
up vote
0
down vote
You know how, see when you assign value it just keep reference form original object but soon you initialize new object with new
alloc
or call retain, it's a copy of original. You can keep retain or use
NSString *entityName = [[NSString alloc] initWithString:[[dic objectForKey:@"appid"] stringValue]];`
Or may be you can define appId
as:
@property (strong, nonatomic) NSString *appId;
in interface and, refer it with self.appId
.
add a comment |
up vote
0
down vote
So i got it to work by doing this:
appId = [[dic objectForKey:@"appid"] retain];
If that compiles, it means that you've turned of ARC (automatic reference counting) for that file or for your whole project. There's little reason to do that these days, especially if you're not very familiar with the manual reference counting rules. The best solution is almost certainly to turn ARC back on and remove the retain
call.
So that means that the appId my assumption was correct and appId was referencing the "dic" object all this time? The question is how can i detach the appId from the "dic" object so it will stay alive even when the object is cleard?
Basically, you were assigning a string to appId
without retaining the string. When the dictionary you got it from was released, it also released all the objects that it contained, including the string that appId
pointed to. With manual reference counting, which you are apparently using, you have to retain
any objects that you keep a reference to, and release
those objects when you no longer need that reference. If you create an object with alloc
/init
or new
or copy
(or some variant of those), you don't need to retain
that object, but you do need to release
it. You can read more about it in Memory Management Rules.
add a comment |
up vote
-2
down vote
Try to alloc appID variable like: [NSString string] in "class.m" and then you can change value of this variable.
You try to assign value to null
New contributor
You can't change the string of the NSString you get back from[NSString string]
— you can only replace it with a different string. And if you're just going to replace it, there's no point in allocating it in the first place.
– Caleb
23 hours ago
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You know how, see when you assign value it just keep reference form original object but soon you initialize new object with new
alloc
or call retain, it's a copy of original. You can keep retain or use
NSString *entityName = [[NSString alloc] initWithString:[[dic objectForKey:@"appid"] stringValue]];`
Or may be you can define appId
as:
@property (strong, nonatomic) NSString *appId;
in interface and, refer it with self.appId
.
add a comment |
up vote
0
down vote
You know how, see when you assign value it just keep reference form original object but soon you initialize new object with new
alloc
or call retain, it's a copy of original. You can keep retain or use
NSString *entityName = [[NSString alloc] initWithString:[[dic objectForKey:@"appid"] stringValue]];`
Or may be you can define appId
as:
@property (strong, nonatomic) NSString *appId;
in interface and, refer it with self.appId
.
add a comment |
up vote
0
down vote
up vote
0
down vote
You know how, see when you assign value it just keep reference form original object but soon you initialize new object with new
alloc
or call retain, it's a copy of original. You can keep retain or use
NSString *entityName = [[NSString alloc] initWithString:[[dic objectForKey:@"appid"] stringValue]];`
Or may be you can define appId
as:
@property (strong, nonatomic) NSString *appId;
in interface and, refer it with self.appId
.
You know how, see when you assign value it just keep reference form original object but soon you initialize new object with new
alloc
or call retain, it's a copy of original. You can keep retain or use
NSString *entityName = [[NSString alloc] initWithString:[[dic objectForKey:@"appid"] stringValue]];`
Or may be you can define appId
as:
@property (strong, nonatomic) NSString *appId;
in interface and, refer it with self.appId
.
answered 23 hours ago
rptwsthi
8,48385292
8,48385292
add a comment |
add a comment |
up vote
0
down vote
So i got it to work by doing this:
appId = [[dic objectForKey:@"appid"] retain];
If that compiles, it means that you've turned of ARC (automatic reference counting) for that file or for your whole project. There's little reason to do that these days, especially if you're not very familiar with the manual reference counting rules. The best solution is almost certainly to turn ARC back on and remove the retain
call.
So that means that the appId my assumption was correct and appId was referencing the "dic" object all this time? The question is how can i detach the appId from the "dic" object so it will stay alive even when the object is cleard?
Basically, you were assigning a string to appId
without retaining the string. When the dictionary you got it from was released, it also released all the objects that it contained, including the string that appId
pointed to. With manual reference counting, which you are apparently using, you have to retain
any objects that you keep a reference to, and release
those objects when you no longer need that reference. If you create an object with alloc
/init
or new
or copy
(or some variant of those), you don't need to retain
that object, but you do need to release
it. You can read more about it in Memory Management Rules.
add a comment |
up vote
0
down vote
So i got it to work by doing this:
appId = [[dic objectForKey:@"appid"] retain];
If that compiles, it means that you've turned of ARC (automatic reference counting) for that file or for your whole project. There's little reason to do that these days, especially if you're not very familiar with the manual reference counting rules. The best solution is almost certainly to turn ARC back on and remove the retain
call.
So that means that the appId my assumption was correct and appId was referencing the "dic" object all this time? The question is how can i detach the appId from the "dic" object so it will stay alive even when the object is cleard?
Basically, you were assigning a string to appId
without retaining the string. When the dictionary you got it from was released, it also released all the objects that it contained, including the string that appId
pointed to. With manual reference counting, which you are apparently using, you have to retain
any objects that you keep a reference to, and release
those objects when you no longer need that reference. If you create an object with alloc
/init
or new
or copy
(or some variant of those), you don't need to retain
that object, but you do need to release
it. You can read more about it in Memory Management Rules.
add a comment |
up vote
0
down vote
up vote
0
down vote
So i got it to work by doing this:
appId = [[dic objectForKey:@"appid"] retain];
If that compiles, it means that you've turned of ARC (automatic reference counting) for that file or for your whole project. There's little reason to do that these days, especially if you're not very familiar with the manual reference counting rules. The best solution is almost certainly to turn ARC back on and remove the retain
call.
So that means that the appId my assumption was correct and appId was referencing the "dic" object all this time? The question is how can i detach the appId from the "dic" object so it will stay alive even when the object is cleard?
Basically, you were assigning a string to appId
without retaining the string. When the dictionary you got it from was released, it also released all the objects that it contained, including the string that appId
pointed to. With manual reference counting, which you are apparently using, you have to retain
any objects that you keep a reference to, and release
those objects when you no longer need that reference. If you create an object with alloc
/init
or new
or copy
(or some variant of those), you don't need to retain
that object, but you do need to release
it. You can read more about it in Memory Management Rules.
So i got it to work by doing this:
appId = [[dic objectForKey:@"appid"] retain];
If that compiles, it means that you've turned of ARC (automatic reference counting) for that file or for your whole project. There's little reason to do that these days, especially if you're not very familiar with the manual reference counting rules. The best solution is almost certainly to turn ARC back on and remove the retain
call.
So that means that the appId my assumption was correct and appId was referencing the "dic" object all this time? The question is how can i detach the appId from the "dic" object so it will stay alive even when the object is cleard?
Basically, you were assigning a string to appId
without retaining the string. When the dictionary you got it from was released, it also released all the objects that it contained, including the string that appId
pointed to. With manual reference counting, which you are apparently using, you have to retain
any objects that you keep a reference to, and release
those objects when you no longer need that reference. If you create an object with alloc
/init
or new
or copy
(or some variant of those), you don't need to retain
that object, but you do need to release
it. You can read more about it in Memory Management Rules.
answered 23 hours ago
Caleb
108k16147237
108k16147237
add a comment |
add a comment |
up vote
-2
down vote
Try to alloc appID variable like: [NSString string] in "class.m" and then you can change value of this variable.
You try to assign value to null
New contributor
You can't change the string of the NSString you get back from[NSString string]
— you can only replace it with a different string. And if you're just going to replace it, there's no point in allocating it in the first place.
– Caleb
23 hours ago
add a comment |
up vote
-2
down vote
Try to alloc appID variable like: [NSString string] in "class.m" and then you can change value of this variable.
You try to assign value to null
New contributor
You can't change the string of the NSString you get back from[NSString string]
— you can only replace it with a different string. And if you're just going to replace it, there's no point in allocating it in the first place.
– Caleb
23 hours ago
add a comment |
up vote
-2
down vote
up vote
-2
down vote
Try to alloc appID variable like: [NSString string] in "class.m" and then you can change value of this variable.
You try to assign value to null
New contributor
Try to alloc appID variable like: [NSString string] in "class.m" and then you can change value of this variable.
You try to assign value to null
New contributor
New contributor
answered yesterday
Nikita Nagatkin
1
1
New contributor
New contributor
You can't change the string of the NSString you get back from[NSString string]
— you can only replace it with a different string. And if you're just going to replace it, there's no point in allocating it in the first place.
– Caleb
23 hours ago
add a comment |
You can't change the string of the NSString you get back from[NSString string]
— you can only replace it with a different string. And if you're just going to replace it, there's no point in allocating it in the first place.
– Caleb
23 hours ago
You can't change the string of the NSString you get back from
[NSString string]
— you can only replace it with a different string. And if you're just going to replace it, there's no point in allocating it in the first place.– Caleb
23 hours ago
You can't change the string of the NSString you get back from
[NSString string]
— you can only replace it with a different string. And if you're just going to replace it, there's no point in allocating it in the first place.– Caleb
23 hours ago
add a comment |
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%2f53372212%2fnsstring-value-not-persistent%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
2
can you add some additional code
– Anbu.karthik
yesterday
Checking at this code tell me there is no issue. Search for
appId
and check if it's value is updated some where else, also show code were you are displaying to value of appId.– rptwsthi
yesterday
Is appId a member variable? If yes, are you calling the functions a and b on the same object?
– SSB95
yesterday
@rptwsthi can it be that the app id value is being cleared when dic (dictionary) is being cleared? So when the net function calls and dic is no longer valid the appId value points to unfilled address?
– Michael A
yesterday
Please show the whole definition. How is that "class variable" declared?
– Sulthan
yesterday