iOS Question This Sub Can't be compiled

shirlun

Active Member
Licensed User
Longtime User
I don't know why this sub can't be compiled, please help, thanks.

B4X:
Sub icSetLastModified(Dir As String, FileName As String, DT As Long) As Boolean

    Dim no As NativeObject = Me
   
    Return no.RunMethod("setlastmodifiedtime::", Array(File.Combine(Dir, FileName), DT))
   
End Sub

#if objc
- (BOOL)setlastmodifiedtime: (NSString*) target :(NSLong) dt {
  NSDictionary *attr = [NSDictionary dictionaryWithObjectsAndKeys: dt, NSFileModificationDate, NULL];
  return [[NSFileManager defaultManager] setAttributes: attr ofItemAtPath: target error: NULL];
}
#end if

The log:

/Users/administrator/Documents/UploadedProjects/<user id>/B4iProject/b4i_icsub.m:2854:51: error: expected a type
- (BOOL)setlastmodifiedtime: (NSString*) target :(NSLong) dt {
^
/Users/administrator/Documents/UploadedProjects/<user id>/B4iProject/b4i_icsub.m:2867:3: warning: passing 'const void *' to parameter of type 'void * _Nullable' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
data.bytes,
^~~~~~~~~~
In module 'UIKit' imported from ../../Libs/iCore.h:7:
In module 'CoreGraphics' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAccessibility.h:8:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.1.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGBitmapContext.h:63:75: note: passing argument to parameter 'data' here
CG_EXTERN CGContextRef __nullable CGBitmapContextCreate(void * __nullable data,
^
1 warning and 1 error generated.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It should be:
B4X:
Sub SetLastModified(Dir As String, FileName As String, DT As Long) As Boolean
   Dim no As NativeObject = Me
   Dim c As NativeObject
   c = c.Initialize("B4ICommon").RunMethod("shared", Null).RunMethod("DateTime", Null)
   Return no.RunMethod("setlastmodifiedtime::", Array(File.Combine(Dir, FileName), c.RunMethod("TicksToNSDate:", Array(DT)))).AsBoolean
End Sub

#if objc
- (BOOL)setlastmodifiedtime:(NSString*) target :(NSDate*) dt {
  NSDictionary *attr = [NSDictionary dictionaryWithObjectsAndKeys: dt, NSFileModificationDate, NULL];
  return [[NSFileManager defaultManager] setAttributes: attr ofItemAtPath: target error: NULL];
}
#end if
 
Last edited:
Upvote 0

shirlun

Active Member
Licensed User
Longtime User
Hi,

The above code generates runtime error, how to correct it ? Thanks.

-------------------------

Application_Start
Application_Active
Error occurred on line: 51 (Main)
-[__NSCFNumber timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x15ddee70
Stack Trace: (
CoreFoundation <redacted> + 150
libobjc.A.dylib objc_exception_throw + 38
CoreFoundation <redacted> + 0
CoreFoundation <redacted> + 702
CoreFoundation _CF_forwarding_prep_0 + 24
Foundation <redacted> + 1582
B4i Example -[b4i_main setlastmodifiedtime::] + 326
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 292
B4i Example +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1780
B4i Example -[B4INativeObject RunMethod::] + 158
B4i Example -[b4i_main _icsetlastmodified:::] + 1294
B4i Example -[b4i_main _page1_resize::] + 2670
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 292
B4i Example +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1780
B4i Example -[B4IShell runMethod:] + 574
B4i Example -[B4IShell raiseEventImpl:method:args::] + 2212
B4i Example -[B4IShellBI raiseEvent:event:params:] + 1442
B4i Example +[B4IObjectWrapper raiseEvent:::] + 220
B4i Example __30-[B4IPanelView layoutSubviews]_block_invoke + 1040
libdispatch.dylib <redacted> + 10
libdispatch.dylib <redacted> + 22
libdispatch.dylib _dispatch_main_queue_callback_4CF + 1532
CoreFoundation <redacted> + 8
CoreFoundation <redacted> + 1590
CoreFoundation CFRunLoopRunSpecific + 516
CoreFoundation CFRunLoopRunInMode + 108
GraphicsServices GSEventRunModal + 160
UIKit UIApplicationMain + 144
B4i Example main + 108
libdyld.dylib <redacted> + 2
)

B4X:
'Code module
#Region  Project Attributes 
    #ApplicationLabel: B4i Example
    #Version: 1.0.0 
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
    #Target: iPhone, iPad
    #MinVersion: 7
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page

End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "Page 1"
    Page1.RootPanel.Color = Colors.White
    NavControl.ShowPage(Page1)
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
   
    Dim n As String
    Dim o As OutputStream
    Dim b(1024) As Byte
   
    n = "test"
    o = File.OpenOutput(File.DirTemp, n, False)
   
    o.WriteBytes(b, 0, b.Length)
    o.Close
   
    icSetLastModified(File.DirTemp, n, DateTime.DateParse("02/23/2007"))
   
    Msgbox(DateTime.Date(File.LastModified(File.DirTemp, n)), "")

End Sub

Sub icSetLastModified(Dir As String, FileName As String, DT As Long) As Boolean

    Dim no As NativeObject = Me
   
    Return no.RunMethod("setlastmodifiedtime::", Array(File.Combine(Dir, FileName), DT)).AsBoolean
   
End Sub

#if objc
- (BOOL)setlastmodifiedtime: (NSString*) target :(long long) dt {
  NSDictionary *attr = [NSDictionary dictionaryWithObjectsAndKeys: @(dt), NSFileModificationDate, NULL];
  return [[NSFileManager defaultManager] setAttributes: attr ofItemAtPath: target error: NULL];
}
#end if
 
Upvote 0

shirlun

Active Member
Licensed User
Longtime User
Same error occured.

B4X:
#if objc
- (BOOL)setlastmodifiedtime: (NSString*) target :(long long) dt {
  NSDictionary *attr = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithLongLong:dt], NSFileModificationDate, NULL];
  return [[NSFileManager defaultManager] setAttributes: attr ofItemAtPath: target error: NULL];
}
#end if
 
Upvote 0
Top