Why my app crashed when called a NSString variable declared globally?











up vote
-2
down vote

favorite












I declared a string variable to be used in another class in the same file, however when I try to display an alert with the string, it crashed.



NSString *str1;

@implementation someClass
-(void) someMethod{
str1 = something; //update the str1 value from .plist
//Alert with str1 in here displayed with no issue
}
@end


Then after the value of str1 is being updated, another class retrieved it as below, here, it crashed



%hook someInterestingClass

%new
-(void) someMethod:(NSNotification*)notification

UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Sample Title"
message:str1
delegate:nil
cancelButtonTitle:@"Sample Title"
otherButtonTitles:nil];
[alert show];
[alert release];
}
%end


However if I globally declare a float like so and display an alert (same with above), it display perfectly fine. Why is NSString so special?



float someValue;


EDIT:
I realized it only crashed if only I try to access it from under %new, but not under %hook










share|improve this question




























    up vote
    -2
    down vote

    favorite












    I declared a string variable to be used in another class in the same file, however when I try to display an alert with the string, it crashed.



    NSString *str1;

    @implementation someClass
    -(void) someMethod{
    str1 = something; //update the str1 value from .plist
    //Alert with str1 in here displayed with no issue
    }
    @end


    Then after the value of str1 is being updated, another class retrieved it as below, here, it crashed



    %hook someInterestingClass

    %new
    -(void) someMethod:(NSNotification*)notification

    UIAlertView *alert = [[UIAlertView alloc]
    initWithTitle:@"Sample Title"
    message:str1
    delegate:nil
    cancelButtonTitle:@"Sample Title"
    otherButtonTitles:nil];
    [alert show];
    [alert release];
    }
    %end


    However if I globally declare a float like so and display an alert (same with above), it display perfectly fine. Why is NSString so special?



    float someValue;


    EDIT:
    I realized it only crashed if only I try to access it from under %new, but not under %hook










    share|improve this question


























      up vote
      -2
      down vote

      favorite









      up vote
      -2
      down vote

      favorite











      I declared a string variable to be used in another class in the same file, however when I try to display an alert with the string, it crashed.



      NSString *str1;

      @implementation someClass
      -(void) someMethod{
      str1 = something; //update the str1 value from .plist
      //Alert with str1 in here displayed with no issue
      }
      @end


      Then after the value of str1 is being updated, another class retrieved it as below, here, it crashed



      %hook someInterestingClass

      %new
      -(void) someMethod:(NSNotification*)notification

      UIAlertView *alert = [[UIAlertView alloc]
      initWithTitle:@"Sample Title"
      message:str1
      delegate:nil
      cancelButtonTitle:@"Sample Title"
      otherButtonTitles:nil];
      [alert show];
      [alert release];
      }
      %end


      However if I globally declare a float like so and display an alert (same with above), it display perfectly fine. Why is NSString so special?



      float someValue;


      EDIT:
      I realized it only crashed if only I try to access it from under %new, but not under %hook










      share|improve this question















      I declared a string variable to be used in another class in the same file, however when I try to display an alert with the string, it crashed.



      NSString *str1;

      @implementation someClass
      -(void) someMethod{
      str1 = something; //update the str1 value from .plist
      //Alert with str1 in here displayed with no issue
      }
      @end


      Then after the value of str1 is being updated, another class retrieved it as below, here, it crashed



      %hook someInterestingClass

      %new
      -(void) someMethod:(NSNotification*)notification

      UIAlertView *alert = [[UIAlertView alloc]
      initWithTitle:@"Sample Title"
      message:str1
      delegate:nil
      cancelButtonTitle:@"Sample Title"
      otherButtonTitles:nil];
      [alert show];
      [alert release];
      }
      %end


      However if I globally declare a float like so and display an alert (same with above), it display perfectly fine. Why is NSString so special?



      float someValue;


      EDIT:
      I realized it only crashed if only I try to access it from under %new, but not under %hook







      objective-c jailbreak






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 17 at 10:38

























      asked Nov 17 at 10:27









      Gregor Isack

      440312




      440312





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53350323%2fwhy-my-app-crashed-when-called-a-nsstring-variable-declared-globally%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53350323%2fwhy-my-app-crashed-when-called-a-nsstring-variable-declared-globally%23new-answer', 'question_page');
          }
          );

          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







          Popular posts from this blog

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          RAC Tourist Trophy